Skip to main content

Build a REST API with Flask

Project description

Flask-RESTly

Build Status Latest version Python versions Coverage Status

Quick start

pip install flask-restly

By default flask-restly uses JSON serializer.

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('/<id>')
    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('/<id>')
    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)
$ 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 for more details.

Settings

Name Default value
RESTLY_SERIALIZER: <flask_restly.serializer.SerializerBase> flask_restly.serializer.json
RESTLY_API_PREFIX: <str> /api/rest
RESTLY_PROTOBUF_MIMETYPE: <str> application/x-protobuf
RESTLY_RATE_LIMIT_REQUESTS_AMOUNT: <int> 100
RESTLY_RATE_LIMIT_WINDOW_SECONDS: <int> 60

Docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flask-restly, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size flask_restly-1.1.0-py3-none-any.whl (17.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size flask-restly-1.1.0.tar.gz (13.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page