To provide services using machine learning with REST API First, let's implement the REST API in Python.
Falcon Python web framework. It's a minor, but it's lightweight and fast.
Building a speed of light Web API server with Falcon Web API with Python + Falcon
Python 3.5.2 Falcon 1.1.0 Cython 0.24.1 (Python acceleration)
You can install it with pip.
pip install falcon
pip install cython
timeapi.py
import json
import falcon
from datetime import datetime
#Create a class and describe the process
class TimeResource(object):
#GET method
def on_get(self, req, resp):
#Write a message
dt=datetime.now() #Times of Day
msg = {
"hour": dt.hour,
"minute": dt.minute,
"second": dt.second
}
#Return message in json format
resp.body = json.dumps(msg)
#app instance creation
app = falcon.API()
#Connect endpoints and classes
app.add_route("/", TimeResource())
if __name__ == "__main__":
#Start the server
from wsgiref import simple_server
httpd = simple_server.make_server("", 8000, app)
httpd.serve_forever()
http://localhost:8000
When you access
{'second': 53, 'hour': 12, 'minute': 1}
The result is displayed as follows.
Recommended Posts