Giter Club home page Giter Club logo

py_autoapi's Introduction

web自动CURD

版本

  • 1.1

前言

动动手设计下表结构,就能自动注入对应API方法;

基于sqlalchemy 与flask框架实现的数据库模块自动生成CURD demo

使用介绍

# 默认为测试sqlite,初始化数据库
python manager.py init_db		

# 启动服务,默认端口 5000	
python manager.py run

# 只需要在app/models.py 中定义 Table,会自动注入CURD API方法
添加新表,需要重新 init_db

方法介绍

获取对象列表

GET http://127.0.0.1:5000/api/models/

获取一个对象

GET http://127.0.0.1:5000/api/models/<string:table>/<int:id>/

创建一个对象

POST http://127.0.0.1:5000/api/models/<string:table>/

修改一个对象

PUT http://127.0.0.1:5000/api/models/<string:table>/<int:id>/

修改部分属性一个对象

PATCH http://127.0.0.1:5000/api/models/<string:table>/<int:id>/

删除一个对象

DELETE http://127.0.0.1:5000/api/models/<string:table>/<int:id>/	

修改与新增功能列表

  • 提取模块校验为装饰器,统一 404、405 返回
  • 修改为了restful api格式
  • 统一使用Base管理所有子类,避免导入model
  • 添加字段类型校验功能(默认值智能校验)

后续

提供api doc,生成在线文档

py_autoapi's People

Contributors

maycap avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

py_autoapi's Issues

路由可以优化一下 兼容 restful 标准

restful 接口的路由一般是这样:
GET http://127.0.0.1:5000/api/models/<tablename> # 获取对象列表
GET http://127.0.0.1:5000/api/models/<tablename>/<id> # 获取一个对象
POST http://127.0.0.1:5000/api/models/<tablename> # 创建一个对象
PUT http://127.0.0.1:5000/api/models/<tablename>/<id> # 修改一个对象
PATCH http://127.0.0.1:5000/api/models/<tablename>/<id> # 部分修改一个对象
DELETE http://127.0.0.1:5000/api/models/<tablename>/<id> # 删除一个对象

我看你代码中 id 好像是在 请求参数中传入的,建议可以放到 url 中。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.