https://github.com/gorzechowski/flask-restly
Library to build REST API with Flask
https://github.com/gorzechowski/flask-restly
flask json protobuf python rest-api
Last synced: 12 months ago
JSON representation
Library to build REST API with Flask
- Host: GitHub
- URL: https://github.com/gorzechowski/flask-restly
- Owner: gorzechowski
- License: mit
- Created: 2018-10-11T14:16:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-16T08:01:30.000Z (about 6 years ago)
- Last Synced: 2025-03-23T21:11:16.422Z (about 1 year ago)
- Topics: flask, json, protobuf, python, rest-api
- Language: Python
- Homepage:
- Size: 92.8 KB
- Stars: 17
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask-RESTly
[](https://travis-ci.org/gorzechowski/flask-restly)
[](https://pypi.org/project/flask-restly)
[](https://pypi.org/project/flask-restly)
[](https://coveralls.io/github/gorzechowski/flask-restly?branch=master)
## Quick start
```
pip install flask-restly
```
By default `flask-restly` uses JSON serializer.
```python
from flask import Flask
from flask_restly import FlaskRestly
from flask_restly.decorator import resource, get, delete
app = Flask(__name__)
rest = FlaskRestly(app)
rest.init_app(app)
@resource(name='employees')
class EmployeesResource:
@get('/')
def get_employee(self, id):
return dict(id=int(id))
@get('/')
def get_employees(self):
return dict(entites=[
dict(id=1),
dict(id=2)
])
@delete('/')
def delete_employee(self, **kwargs):
return
with app.app_context():
EmployeesResource()
if __name__ == "__main__":
app.run(host='127.0.0.1', port=5001, debug=True)
```
```bash
$ python main.py
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 210-167-642
* Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
```
## Features
* Decorators-based routing
* JSON and Protobuf built-in serialization
* Custom serializer support
* Authorization and authentication decorators
* Automatic REST-like response codes
* API versioning
* Rating limits
## Todo
* HATEOAS/HAL
## Usage
Please see [examples](/examples) for more details.
### Settings
| Name | Default value |
| -----------------------------------------------------------: | :--------------------------- |
| RESTLY_SERIALIZER: `` | flask_restly.serializer.json |
| RESTLY_API_PREFIX: `` | /api/rest |
| RESTLY_PROTOBUF_MIMETYPE: `` | application/x-protobuf |
| RESTLY_RATE_LIMIT_REQUESTS_AMOUNT: `` | 100 |
| RESTLY_RATE_LIMIT_WINDOW_SECONDS: `` | 60 |
### Docs
* [Authentication](/docs/Authentication.md)
* [Authorization](/docs/Authorization.md)
* [Decorators](/docs/Decorators.md)
* [Exceptions](/docs/Exceptions.md)
* [Protobuf](/docs/Protobuf.md)
* [RateLimits](/docs/RateLimits.md)