Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
120 lines (84 sloc) 2.96 KB

Hosts

The hosts argument contains a dictionary of domains and vroots.

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

Hosts dictionary elements

*:wildcard matching all HTTP_HOSTS
default:vroot

To support multi-tenancy the hosts dictionary is needed.

A dictionary structure is formed by key: value elements, in this case the key is used for specifying the 'host' and the value to specify the vroot

Hosts structure & vroot

The wildcard character * can be used, for example:

  • line 2 matches any host * and will be served on vroot 'default'
  • line 3 matches any host ending with zunzun.io and will be served on vroot 'default'
  • line 4 matches host ejemplo.org and will be server on vroot 'ejemplo_org'
  • line 5 matches host api.ejemplo.org and will be served on vroot 'api_ejemplo_org'

Notice that the vroot values use _ as separator instead of a dot, this is to prevent conflicts on how python read files. for example this request:

http://api.ejemplo.org/v0/gevent

Internally will be calling something like:

import my_api.api_ejemplo_org.v0.zun_gevent.zun_gevent

Directory structure

The API directory structure for this example would be:

virtual roots (vroot)

default:line 2, 3
ejemplo_org:line 4
api_ejemplo_org:line 5