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
File details
Details for the file fastapi_restful_rsp-0.1.12.tar.gz
.
File metadata
- Download URL: fastapi_restful_rsp-0.1.12.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a77d220bf9e1bee2118bd03c5950670464a8e9afc923697232ef8430a47291e0 |
|
MD5 | 00da8d03a4394b2fabc0ce9b06b7c771 |
|
BLAKE2b-256 | 2cef9b8e92fe8880f4eb09555728c5711a98686a2fdefe6b348b061374cc69ca |
File details
Details for the file fastapi_restful_rsp-0.1.12-py3-none-any.whl
.
File metadata
- Download URL: fastapi_restful_rsp-0.1.12-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a56aeda1b8cac1ce0db2d8696365ef50a77fcb1955bc841530e670e92e3285 |
|
MD5 | d36d7ec46a8c4578db45556afc1c1eb1 |
|
BLAKE2b-256 | effdf7215a4e2dad5d18ca545f921458051e77baeea4a90d08047eb3ff16d743 |