How it works

There really isn't a lot of code, which is the beauty of Flask-RESTful.  The code begins with importing of flask and flask_restful.

from flask import Flaskfrom flask_restful import Resource, Api

These are followed with code to set up the initial configuration of Flask-RESTful:

app = Flask(__name__)api = Api(app)

Next comes a definition of a class which represents the implementation of our API:

class JobListing(Resource):    def get(self, job_listing_id):        print("Request for job listing with id: " + job_listing_id)        return {'YouRequestedJobWithId': job_listing_id}

What we will have Flask-RESTful do is map HTTP requests to methods in this class.  Specifically, by convention GET requests will be mapped to member functions named get

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.