Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created October 13, 2015 01:35
Show Gist options
  • Save hirokiky/ae5323c2e8dea831d5dd to your computer and use it in GitHub Desktop.
Save hirokiky/ae5323c2e8dea831d5dd to your computer and use it in GitHub Desktop.
Trying falcon for proxy server

Falcon trying

http://falconframework.org/

pip install falcon
pip install requests
pip install gunicorn
gunicorn -b 127.0.0.1:8001 slow:api
gunicorn proxy:api

Accessing to 127.0.0.1:8000/proxy will take 5 sec.

import json
import requests
import falcon
class ProxyResource:
def on_get(self, req, resp):
proxyed = requests.get('http://127.0.0.1:8001/quote')
resp.body = proxyed.text
api = falcon.API()
api.add_route('/proxy', ProxyResource())
import json
import time
import falcon
class QuoteResource:
def on_get(self, req, resp):
"""Handles GET requests"""
time.sleep(5)
quote = {
'quote': 'I\'ve always been more interested in the future than in the past.',
'author': 'Grace Hopper'
}
resp.body = json.dumps(quote)
api = falcon.API()
api.add_route('/quote', QuoteResource())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment