Skip to main content

Wrap fastapi endpoints with RESTful API

Modern frontend frameworks encourage backend developers to follow RESTful API design. This package wraps fastapi endpoints with following structure:

{
  "data": {
    ...
  },
  "code": 200,
  "message": ""
}

and modify fastapi generated OpenAPI documentation to reflect the change.

Installation

pip install fastapi-restful-rsp

Usage

from fastapi import FastAPI
from fastapi_restful_rsp import restful_response

app = FastAPI()

@app.get("/foo/")
@restful_response
def foo()-> str:
    return "Hello World"

Custom response structure

You can customize the response structure by passing data_name, code_key, message_name to restful_response decorator.

restful_response = create_restful_rsp_decorator(
    data_name="data", code_name="my_code", message_name="message", param_dict={"status": (str, "success")}
)

@app.get("/foo/")
@restful_response
def foo()-> str:
    return "Hello World"

Metadata

Release files for fastapi-restful-rsp 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-restful-rsp 0.1.13
File Size Uploaded
fastapi_restful_rsp-0.1.13.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-restful-rsp 0.1.13
File Interpreter ABI Platform
fastapi_restful_rsp-0.1.13-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / fastapi_restful_rsp-0.1.13.tar.gz

Download URL fastapi_restful_rsp-0.1.13.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
884b516ef6e8f2a291529f8643f61ffffb4fdcba6bbe481b769954b1375ab12d
BLAKE2b-256 checksum
How to use checksums
de1877490a7aff8d0833c292956c420138001ae4602b0fa92e49ec03180cb816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / fastapi_restful_rsp-0.1.13-py3-none-any.whl

Download URL fastapi_restful_rsp-0.1.13-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b398b7301fe351d8e420271730e94925b13537c80301706cbb4c4db234fd86d
BLAKE2b-256 checksum
How to use checksums
2b6af5ba710c82fca4bd4a845d8210b8f08b7170ea4730b5e3967af300125202
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 release files

0.1.12

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page