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.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0893ff18bc2d69de5ef8469dca2757b7fc21eebaeff02dd524023a6418cd18c2 |
|
MD5 | 5d349635edad1a2579a77aabfa664906 |
|
BLAKE2b-256 | cbc3dd2eedcc316b9a68726f7598efe9b09faf2148dc1e754abbabd8937300a5 |
Close
Hashes for fastapi_restful_rsp-0.1.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a1eaef41751b82344365cc667f27cd0f510d526dcdcfca95e2c6cb73a55a4db |
|
MD5 | ead594cfbe86226671994d2f1bf20e76 |
|
BLAKE2b-256 | 75406d6f6de34c4b6fe0354d8dbe1db8b02caf299d60d14cb9f6917cdec3b270 |