Flask-RESTful
is an excellent Flask extension that can be used
for quickly building REST APIs. In this tutorial we will
see how to develop REST APIs with Flask-RESTful
.
For the demo purpose this article is using dummy dictionary, however same API can be configured
for data coming from Databases or any other sources.
Flask
and Flask-RESTful
libraries
pip install Flask
pip install Flask-RESTful
from flask import Flask, request, jsonify
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
dummy_data = {
"FirstName": "Test-User",
"LastName": "user",
"Age": "25"
}
class DummyAPI(Resource):
def get(self):
data = jsonify(dummy_data)
return data
api.add_resource(DummyAPI, '/dummydata')
if __name__ == '__main__':
app.run(debug=True)
python app.py
GET
request as shown
below.
Category: Python