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)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_restful_rsp-0.1.13.tar.gz | 2.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|