Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonarsli/flask-restapi
Flask-RESTAPI is an extension for validate and make OpenAPI docs.
https://github.com/jonarsli/flask-restapi
flask flask-restapi openapi3 pydantic python python3 swagger swagger-ui
Last synced: 28 days ago
JSON representation
Flask-RESTAPI is an extension for validate and make OpenAPI docs.
- Host: GitHub
- URL: https://github.com/jonarsli/flask-restapi
- Owner: jonarsli
- License: mit
- Created: 2021-06-14T07:07:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T06:24:19.000Z (over 1 year ago)
- Last Synced: 2024-09-28T18:41:00.335Z (about 1 month ago)
- Topics: flask, flask-restapi, openapi3, pydantic, python, python3, swagger, swagger-ui
- Language: Python
- Homepage: https://jonarsli.github.io/flask-restapi/
- Size: 735 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask-RESTAPI
[![license](https://img.shields.io/github/license/jonarsli/flask-restapi.svg)](https://github.com/jonarsli/flask-restapi/blob/master/LICENSE)
[![pypi](https://img.shields.io/pypi/v/flask-restapi.svg)](https://pypi.python.org/pypi/flask-restapi)[Flask-RESTAPI document](https://jonarsli.github.io/flask-restapi/)
Flask-RESTAPI is an extension for Flask that is a database-agnostic framework library for creating REST APIs. It is a lightweight abstraction that works with your existing ORM/libraries.
It use pydantic to validate and serialize data. OpenAPI document can be automatically generated through the python decorator and it supports swagger ui display.
Pydantic are used to validate and serialize parameters. For details, please refer to the [pydantic documentation](https://pydantic-docs.helpmanual.io/).
## Installation
```bash
pip install flask-restapi
```## Example
```python
from flask import Flask
from flask.views import MethodView
from pydantic import BaseModelfrom flask_restapi import Api, RequestParametersType
app = Flask(__name__)
api = Api(app)class UserGetSpec(BaseModel):
name: strclass UserResponseSpec(BaseModel):
id: int
name: strclass User(MethodView):
@api.query(UserGetSpec)
@api.response(UserResponseSpec)
def get(self, parameters: RequestParametersType):
"""Get a user name and id"""
user_name = parameters.query.name
return UserResponseSpec(id=1, name=user_name)app.add_url_rule("/user", view_func=User.as_view("user"))
```
## Swagger API docs
Now go to http://localhost:5000/docs
![](docs/images/example.png)