Fast restful API based on FastAPI and TortoiseORM.
pip install fastapi-rest
First, define your ListView
resource.
from fastapi_rest.resource import ListView
class UserList(ListView):
model = User
fields = ("name", "age")
Second, include router to your app.
app.include_router(UserList.as_router())
Now, you can visit the endpoint /user
to get user list.
Export the endpoint GET /{resource}
.
class ListView(Resource):
paginator: Paginator = Paginator()
fields: Optional[Tuple[str, ...]] = None
exclude: Optional[Tuple[str, ...]] = None
queryset: Optional[QuerySet] = None
query: Optional[Type[BaseModel]] = None
Export the endpoint GET /{resource}/{pk}
.
class DetailView(Resource):
fields: Optional[Tuple[str, ...]] = None
exclude: Optional[Tuple[str, ...]] = None
Export the endpoint POST /{resource}
.
class CreateView(Resource):
schema: Optional[Type[BaseModel]] = None
Export the endpoint PUT /{resource}/{pk}
.
class UpdateView(Resource):
schema: Type[BaseModel]
Export the endpoint DELETE /{resource}/{pk}
.
class DeleteView(Resource):
pass
You can see the examples here.
This project is licensed under the Apache2.0 License.