Flask-RESTful

0.3.10 · maintenance · verified Thu Apr 09

Flask-RESTful is an extension for Flask that simplifies the creation of REST APIs by providing building blocks like Resources for organizing endpoints and `reqparse` for input validation. The current stable version is 0.3.10, released in May 2023. While still available, the project appears to be in maintenance mode with infrequent updates and hasn't seen major feature releases since 2014.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple Flask-RESTful API. It defines two resources: one for a 'Hello, World!' message at the root path and another to calculate the square of an integer at `/square/<num>`. To run, save as `app.py` and execute `python app.py`. Access `http://127.0.0.1:5000/` for the greeting or `http://127.0.0.1:5000/square/5` for the square calculation.

from flask import Flask
from flask_restful import Resource, Api

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

class HelloWorld(Resource):
    def get(self):
        return {'message': 'Hello, World!'}

class Square(Resource):
    def get(self, num):
        return {'square': num**2}

api.add_resource(HelloWorld, '/')
api.add_resource(Square, '/square/<int:num>')

if __name__ == '__main__':
    app.run(debug=True)

view raw JSON →