About Me
-
Mike Brown
-
Your Favorite Organizer
-
Python Backend + DevOps
-
Python Lead @ Excella Consulting
Background
In January 2017...
{
"text": "mike made the coolest API",
"search": "sarcastic wonka"
}
Original Flask
@app.route('/', methods = ['GET', 'POST'])
def giffer():
if request.method == 'POST':
data = request.data
gif_file = gif_factory.create(**data)
return send_file(gif_file)
else:
return get_guide_text()
The Output
The Original Contestants
-
Sanic - Asynchronous/Fast
-
Hug - Simplified/Self Documenting
Sanic
-
Python 3 required
-
Async/Await syntax
-
"Faster than Node"
@app.route('/', methods = ['POST'])
async def giffer(request):
data = request.json
gif_file = await gif_factory.create(**data)
return file(gif_file, mime_type='image/gif')
Hug
-
Python 3 required
-
Type Annotations
-
Autogenerated documentation
-
"make developing an API as simple as possible"
@hug.post('/', output=hug.output_format.gif_image)
def giffer_post(search: input_search, text: input_text,
text_width: int=60):
return gif_factory.create(search=search, text=text,
text_width=text_width)
Type Annotations!
API Star
By Tom Christie
Who's Tom Christie?
API Star:
-
Python 3 required
-
Type Annotations
-
Autogenerated documentation
-
"Faster than nodejs"
-
Coming soon: Await/Async
How So Fast?
def show_request(request: http.Request):
return {
'method': request.method,
'url': request.url,
'headers': dict(request.headers)
}
def show_query_params(query_params: http.QueryParams):
return {
'params': dict(query_params)
}
def show_user_agent(user_agent: http.Header):
return {
'user-agent': user_agent
}
API Star:
Other "kitchen sink" features
- template/static files
- Django ORM/SQLAlchemy
- autogenerated Swagger schema
- autogenerated JavaScript and Python client libraries
Demo Time
Questions?
How To Make An API In 2017 v2
By m3brown
How To Make An API In 2017 v2
- 1,054