Building RESTful services with Flask-RESTful
The flask-RESTful
module uses the class-based view strategy of Flask to build RESTful services. It provides a Resource
class to create custom resources to build from the ground up HTTP-based services instead of endpoint-based routes.
This chapter specifies another application, ch04-api
, that implements RESTful endpoints for managing user complaints and related details. Here’s one of the resource-based implementations of our application’s API endpoints:
from flask_restful import Resource class ListComplaintRestAPI(Resource): def get(self): repo = ComplaintRepository(db_session) records = repo.select_all() complaint_rec = [rec.to_json() for rec in records] return make_response(jsonify(complaint_rec), 201)...