REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs.
Flask is a simple, yet very powerful Python web framework.
Standard python distribution doesn't contain flask. Install flask using pip
PS D:\> pip install flask
Collecting flask
Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
100% |████████████████████████████████| 92kB 166kB/s
The below service returns "Hello World" Text when user access it.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
The script gets executed and embedded webserver bound to port 5000
$ python rest_api_demo.py
* Restarting with stat
* Debugger is active!
* Debugger PIN: 415-348-367
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [02/Nov/2017 09:37:27] "GET / HTTP/1.1" 200 -
curl - cURL is a command line tool to browse web pages or consume http services
Using Chrome browser