Hosts¶
The hosts
argument contains a dictionary of domains and vroots.
A very basic API, contents of file app.py can be:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import zunzuncito
root = 'my_api'
versions = ['v0', 'v1']
hosts = {'*': 'default'}
routes = {'default':[
('/my/?.*', 'ip_tools', 'GET')
]}
app = zunzuncito.ZunZun(root, versions, hosts, routes, debug=True)
|
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:
1 2 3 4 5 6 | hosts = {
'*': 'default',
'*.zunzun.io': 'default',
'ejemplo.org': 'ejemplo_org',
'api.ejemplo.org': 'api_ejemplo_org'
}
|
- 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /home/
`--zunzun/
|--app.py
`--my_api
|--__init__.py
|--default
| |--__init__.py
| `--v0
| |--__init__.py
| `--zun_default
| |--__init__.py
| `--zun_default.py
|--ejemplo_org
| |--__init__.py
| `--v0
| |--__init__.py
| `--zun_default
| |--__init__.py
| `--zun_default.py
`--api_ejemplo_org
|--__init__.py
`--v0
|--__init__.py
|--zun_gevent
| |--__init__.py
| `--zun_gevent.py
`--zun_default
|--__init__.py
`--zun_default.py
|
A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.
Donating helps ensure continued support, development and availability.
comments powered by Disqus