pip install flask-restless
python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
db.create_all()
api_manager = APIManager(app, flask_sqlalchemy_db=db)
api_manager.create_api(User, methods=['GET', 'POST', 'DELETE'])
if __name__ == '__main__':
app.run()
python
api_manager.create_api(User, methods=['GET', 'POST'], url_prefix='/api/v1', collection_name='users')
python
def authenticate(*args, **kw):
def authorize(*args, **kw):
api_manager.create_api(User, methods=['GET', 'POST'], preprocessors={
'GET_SINGLE': [authenticate],
'GET_MANY': [authenticate],
'POST': [authenticate, authorize]
})