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"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_restful_rsp-0.1.13.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_restful_rsp-0.1.13-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_restful_rsp-0.1.13.tar.gz.

File metadata

  • Download URL: fastapi_restful_rsp-0.1.13.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastapi_restful_rsp-0.1.13.tar.gz
Algorithm Hash digest
SHA256 884b516ef6e8f2a291529f8643f61ffffb4fdcba6bbe481b769954b1375ab12d
MD5 2f592fdf2f2c9358bbe9fd59ac8487dc
BLAKE2b-256 de1877490a7aff8d0833c292956c420138001ae4602b0fa92e49ec03180cb816

See more details on using hashes here.

File details

Details for the file fastapi_restful_rsp-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_restful_rsp-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 1b398b7301fe351d8e420271730e94925b13537c80301706cbb4c4db234fd86d
MD5 9805ddd3afbe56902639d67c4693c42a
BLAKE2b-256 2b6af5ba710c82fca4bd4a845d8210b8f08b7170ea4730b5e3967af300125202

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page