Introducing the Eve REST API Framework.
FOSDEM 2014, Brussels
PyCon Sweden 2014, Stockholm
PyCon Italy 2014, Florence
Python Meetup, Helsinki
EuroPython 2014, Berlin
12. #1 run.py
from eve import Eve
app = Eve()
!
if __name__ == '__main__':
app.run()
13. #2 settings.py
# just a couple API endpoints with no custom
# schema or rules. Will just dump from people
# and books db collections
!
DOMAIN = {
‘people’: {}
‘books’: {}
}
14. #3 launch the API
$ python run.py
* Running on http://127.0.0.1:5000/
22. settings.py
# let’s also add some validation rules
!
DOMAIN['people']['schema'] = {
'name': {
'type': 'string',
'maxlength': 50,
'unique': True}
'email': {
'type': 'string',
'regex': '^S+@S+$'},
'location': {
'type': 'dict',
'schema': {
'address': {'type': 'string'},
'city': {'type': 'string'}}},
'born': {'type': ‘datetime'}}
THIS REGEX SUCKS. DON’T USE IN PRODUCTION
23. settings.py
# allow write access to API endpoints
# (default is [‘GET’] for both settings)
!
# /people
RESOURCE_METHODS = ['GET','POST']
!
# /people/<id>
ITEM_METHODS = ['GET','PATCH','PUT','DELETE']
24. settings.py
# allow write access to API endpoints
# (default is [‘GET’] for both settings)
!
# /people
RESOURCE_METHODS = ['GET','POST']
!
# /people/<id>
ITEM_METHODS = ['GET','PATCH','PUT','DELETE']
ADD/CREATE ONE OR MORE ITEMS
25. settings.py
# allow write access to API endpoints
# (default is [‘GET’] for both settings)
!
# /people
RESOURCE_METHODS = ['GET', 'POST']
!
# /people/<id>
ITEM_METHODS = ['GET','PATCH','PUT','DELETE']
EDIT ITEM
26. settings.py
# allow write access to API endpoints
# (default is [‘GET’] for both settings)
!
# /people
RESOURCE_METHODS = ['GET', 'POST']
!
# /people/<id>
ITEM_METHODS = ['GET','PATCH','PUT','DELETE']
REPLACE ITEM
27. settings.py
# allow write access to API endpoints
# (default is [‘GET’] for both settings)
!
# /people
RESOURCE_METHODS = ['GET', 'POST']
!
# /people/<id>
ITEM_METHODS = ['GET','PATCH','PUT','DELETE']
YOU GUESSED IT
28. settings.py
# a few more config options
!
DOMAIN[‘people’].update(
{
‘item_title’: ‘person’,
‘cache_control’: ‘max-age=10,must-revalidate,
‘cache_expires’: 10,
‘additional_lookup’: {
‘url’: ‘regex)”[w]+”)’,
‘field’: ‘name’
}
)
66. DATA INTEGRITY / CONCURRENCY
$ curl -X PATCH -i <url>
-H “If-Match: 206fb4a39815cc0ebf48b2b52d7…”
-d '{"firstname": “ronald"}'
!
HTTP/1.1 200 OK
UPDATE ALLOWED IF CLIENT AND SERVER ETAG MATCH
79. SECURITY AT A GLANCE
• global authentication
• custom endpoint auth
• public enpoints and methods
• role based access control
• user restricted resource access
88. EVENT HOOKS AT A GLANCE
• POST on_insert/on_inserted
• GET on_fetch/on_fetched
• PATCH on_update/on_updated
• PUT on_replace/on_replaced
• DELETE on_delete/on_deteled
• on_pre_<method>; on_post_<method>
97. {48: <you name here>}
Bryan Cattle Christoph Witzany Daniele Pizzolli
dccrazyboy Dong Wei Ming Florian Rathgeber Francisco
Corrales Morales Garrin Kimmell Gianfranco Palumbo Jaroslav
Semančík Jean Boussier John Deng Jorge Puente Sarrín
Josh Villbrandt Julien Barbot Ken Carpenter Kevin
Bowrin Kracekumar Nicolas Bazire Nicolas Carlier Ondrej
Slinták Petr Jašek Paul Doucet Robert Wlodarczyk Roberto Pasini
Ronan Delacroix Roy Smith Ryan Shea Samuel Sutch
Stanislav Heller Thomas Sileo Tomasz Jezierski Xavi Cubillas