Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/long2ice/fastapi-rest
Fast restful API based on FastAPI and TortoiseORM
https://github.com/long2ice/fastapi-rest
fastapi rest rest-api restful-api tortoise-orm
Last synced: 21 days ago
JSON representation
Fast restful API based on FastAPI and TortoiseORM
- Host: GitHub
- URL: https://github.com/long2ice/fastapi-rest
- Owner: long2ice
- License: apache-2.0
- Created: 2021-06-28T14:32:05.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-30T15:32:56.000Z (over 3 years ago)
- Last Synced: 2024-12-03T09:53:03.305Z (about 1 month ago)
- Topics: fastapi, rest, rest-api, restful-api, tortoise-orm
- Language: Python
- Homepage: https://github.com/long2ice/fastapi-rest
- Size: 33.2 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fastapi-rest
[![image](https://img.shields.io/pypi/v/fastapi-rest.svg?style=flat)](https://pypi.python.org/pypi/fastapi-rest)
[![image](https://img.shields.io/github/license/long2ice/fastapi-rest)](https://github.com/long2ice/fastapi-rest)
[![image](https://github.com/long2ice/fastapi-rest/workflows/pypi/badge.svg)](https://github.com/long2ice/fastapi-rest/actions?query=workflow:pypi)
[![image](https://github.com/long2ice/fastapi-rest/workflows/ci/badge.svg)](https://github.com/long2ice/fastapi-rest/actions?query=workflow:ci)## Introduction
Fast restful API based on FastAPI and TortoiseORM.
## Install
```shell
pip install fastapi-rest
```## Quick Start
First, define your `ListView` resource.
```python
from fastapi_rest.resource import ListViewclass UserList(ListView):
model = User
fields = ("name", "age")
```Second, include router to your app.
```python
app.include_router(UserList.as_router())
```Now, you can visit the endpoint `/user` to get user list.
### ListView
Export the endpoint `GET /{resource}`.
```python
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
```### DetailView
Export the endpoint `GET /{resource}/{pk}`.
```python
class DetailView(Resource):
fields: Optional[Tuple[str, ...]] = None
exclude: Optional[Tuple[str, ...]] = None
```### CreateView
Export the endpoint `POST /{resource}`.
```python
class CreateView(Resource):
schema: Optional[Type[BaseModel]] = None
```### UpdateView
Export the endpoint `PUT /{resource}/{pk}`.
```python
class UpdateView(Resource):
schema: Type[BaseModel]
```### DeleteView
Export the endpoint `DELETE /{resource}/{pk}`.
```python
class DeleteView(Resource):
pass
```## Reference
You can see the examples [here](./examples).
## License
This project is licensed under the [Apache2.0](https://github.com/long2ice/fastapi-rest/blob/master/LICENSE) License.