Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
242 lines (164 sloc) 6.1 KB

Quick Start

URI parts:

http://api.zunzun.io/v0/get/client/ip
\__________________/\_/\__/\_____/\_/
         |           |   | \__|____|/
         |       version |    |  | |
   host (default)    resource |path|
                              |    |
                           path[0] |
                                   |
                                path[1]

ZunZun translates that URI to:

my_api.default.v0.zun_get.zun_client.zun_client

This is the directory structure:

API directory structure

app.py:application python file.
my_api:The root directory of the API.
default:The vroot directory.
v0:Directory for default API resources or for version 0 when specified.
v1:Directory for API resources version 1
get:API resource
client:Path

Inside directory /home/zunzun there is a file called app.py and a directory my_api.

For a very basic API, contents of file app.py can be:

  • line 3 defines the "document root" for your API
  • line 7 gives multitenant support, in the example all "*" is going to be handled by the 'default' vroot
  • line 11 contains a regex matching all the requests, it is at the bottom because in the routes, order matters.

The contents of the my_api contain python modules (API Resources) for example the content of module zun_default/zun_default.py is:

.. seealso::

   `Basic template <http://docs.zunzun.io/en/latest/resource/dispatch_method.html#basic-template>`_


How to run it

Zunzuncito is compatible with any WSGI server, next are some examples of how to run it with uWSGI, and Gunicorn, Twisted.

uWSGI

Listening on port 8080:

uwsgi --http :8080 --wsgi-file app.py --callable app --master

Listening on port 80 with 2 processes and stats on http://127.0.0.1:8181:

uwsgi --http :80 --wsgi-file app.py --callable app --master --processes 2 --threads 2 --stats 127.0.0.1:8181 --harakiri 30

Using a .ini file

TRACK_ID

route-run:adds a custom tracking ID, see uwsgi InternalRouting

For this case, to append to all your responses the Request-ID header run the app like this:

app = zunzuncito.ZunZun(root, versions, hosts, routes, rid='TRACK_ID')

Gunicorn

Listening on port 8080:

gunicorn -b :8080  app:app

Listening on port 8080 with 2 processes:

gunicorn -b :8080 -w2 app:app

GAE

Tu have a ZunZun instance up and running in Google App Engine you can use the following configuration.

Contents of the app.yaml file:

main.app

script:main is the main.py file app is the instance of zunzun

Note

When using GAE the global unique identifier per request is: REQUEST_LOG_ID

For this case, to append to all your responses the Request-ID header run the app like this:

app = zunzuncito.ZunZun(root, versions, hosts, routes, rid='REQUEST_LOG_ID')