Home

Introduction

Rest-Utils 为使用 SQLAlchemy (or Flask-SQLAlchemy) 定义的数据库模型提供简单的Restful APIs生成。 生成的API以JSON格式转换数据。内部使用 marshmallow 使得复用数据转换非常简单。

For more information, see the

Install

# 可以从页面下载。不过推荐使用pip,virtualenv安装。
pip install Rest-Utils

Quick Start

pip install Rest-Utils flask_sqlalchemy
wget https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite_AutoIncrementPKs.sqlite
import flask
from flask_sqlalchemy import SQLAlchemy
from rest_utils import APIManager

app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./Chinook_Sqlite_AutoIncrementPKs.sqlite'
db = SQLAlchemy(app)
api = APIManager(app, db=db)
api.auto_create()
app.run()
curl http://127.0.0.1:5000/api/Track?_num=20&_expand=1

详细使用参见:快速开始