FastAPI RESTful

0.6.0 · active · verified Thu Apr 16

FastAPI-RESTful provides helper utilities to streamline FastAPI development, particularly for building RESTful APIs using class-based views (CBV) and resource inferring routers. It aims to reduce boilerplate when defining API endpoints and integrates well with common patterns like SQLAlchemy sessions. The current version is 0.6.0, and it has a moderate release cadence, with minor versions released every few months, often incorporating dependency updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a class-based view (CBV) using `fastapi-restful`'s `Resource` and `InferringRouter`. The `cbv` decorator automatically registers methods as API endpoints based on their names (e.g., `get_hello` becomes a GET endpoint at `/hello`).

from fastapi import FastAPI
from fastapi_restful.resource import Resource
from fastapi_restful.cbv import cbv
from fastapi_restful.inferring_router import InferringRouter

app = FastAPI()
router = InferringRouter()

@cbv(router)
class HelloWorldResource(Resource):
    def get_hello(self):
        return {"message": "Hello World from CBV!"}

app.include_router(router)

# To run this:
# 1. Save as main.py
# 2. uvicorn main:app --reload
# 3. Access http://127.0.0.1:8000/hello

view raw JSON →