Skip to content
Bryan edited this page Jul 17, 2013 · 4 revisions

Any WSGI web server requires a Python callable. Here's how to create an instance of CurryProxy to point your web server towards:

callable.py:

from curryproxy import CurryProxy

curry_proxy = CurryProxy(routes_file='routes.json',
                         logging_config='logging.conf')

callable.py is specifying custom route and logging configuration files; these parameters may be omitted and CurryProxy will look for them by default in /etc/curryproxy/routes.json and /etc/curryproxy/logging.conf, respectively. Here are some examples of these configuration files:

routes.json:

[
    {
        "route": "http://127.0.0.1:8000/v1.0/",
        "forwarding_url": "https://1.example.com/v1.0/"
    },
    {
        "route": "http://127.0.0.1:8000/{Endpoint_IDs}/v1.0/",
        "endpoints": [
            {
                "id": "1",
                "url": "https://1.example.com/v1.0/"
            },
            {
                "id": "2",
                "url": "https://2.example.com/v1.0/"
            }
        ],
        "priority_errors": [401]
    }
]

logging.conf (a standard Python logging configuration file):

[loggers]
keys=root

[handlers]
keys=console_handler

[formatters]
keys=simple_formatter

[logger_root]
level=INFO
handlers=console_handler

[handler_console_handler]
class=StreamHandler
formatter=simple_formatter
level=INFO
args=(sys.stdout,)

[formatter_simple_formatter]
format=%(asctime)s - %(levelname)s - %(message)s
datefmt=

Finally, running from the same directory where callable.py is located, you can start a web server running CurryProxy with the following command (this example uses gunicorn):

gunicorn -b 127.0.0.1:8000 callable:curry_proxy

Clone this wiki locally