No project description provided
Project description
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"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for fastapi_restful_rsp-0.1.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cc7db9cee19132ab40e3e89f8b87bb31147559db794d3ed4778e7b8cf02ade3 |
|
MD5 | e8b3929a6cc4c45346a8fb39a455850b |
|
BLAKE2b-256 | 461685c39d378fe07a7386ec693e73e54c5db58f7b0bd7d5ac1a114569916486 |
Close
Hashes for fastapi_restful_rsp-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d8b055c949ee1b9f9418e938d2dcd72dbf65399304872ee1df5983e9f11d7d6 |
|
MD5 | a474aa68e1fd2fbe8f7f595eecbdb306 |
|
BLAKE2b-256 | c705f20ac9d8a0f1ad0e384a9243563f01d7ddb2db7183c1aae7e94f03bc237b |