Just the right article was published. Python --Building a speed of light Web API server with Falcon --Qiita
Falcon - The minimalist Python WSGI framework falconry/falcon
In this article, it was written using simple_server
, but here I will use the recommended Gunicorn.
Gunicorn - Python WSGI HTTP Server for UNIX
benoitc/gunicorn
All together with pip
pip install --upgrade cython falcon gunicorn
Falcon Web Framework (http://falconframework.org) With reference to
sample.py
# -*- coding: utf-8 -*-
# sample.py
import falcon
import json
class ItemsResource:
def on_get(self, req, resp):
"""Handles GET requests"""
items = {
'title': 'Python+Web API with Falcon',
'tags': [
{
'name': 'Python','versions':[]
},
{
'name': 'Falcon','vresions':[]
}
]
}
resp.body = json.dumps(items,ensure_ascii=False)
api = falcon.API()
api.add_route('/items', ItemsResource())
When you access with wget http: // localhost: 8000 / items
{"tags": [{"name": "Python", "versions": []}, {"vresions": [], "name": "Falcon"}], "title": "Python+Web API with Falcon"}
I heard that I was able to get it safely. I'm happy.
Recommended Posts