Giter Club home page Giter Club logo

api-server-flask's Introduction

api-server-flask

基于Flask框架上集成与封装了一些便捷功能,用于快速编写一个API服务。

实现功能

  • 请求表单参数校验
  • 返回数据模版化
  • 自动根据上述配置动态生成文档
  • 方便配置Authenticate功能

使用示例

from kernel.controller import BaseController

controller = BaseController(
    name='name', import_name=__name__, prefix='/prefix') 


@controller.post('/post-method')
@controller.login_required()
@controller.add_apidoc()
def post_method():
    pass

请求参数校验

from kernel.controller.webargs import fields

post_form = {
    'arg': fields.Str(required=True)
}
    
@controller.get('/use-args')
@controller.use_args(post_form, code=403)
def use_args(parsed):
    # 校验后的参数会以名为parsed的字典传入
    pass

结果模版返回

from kernel.response import Response, THolder
    
response = {
    'res': THolder('res'),
    'user': {
        'id': THolder('user.id'),
        'name': THolder('user.name')
    }
}

@controller.get('/render-template')
@controller.add_apidoc(response=response)
def render_template():
    user = {'id': 1, 'name': 'user'}
    return Response.render(response, res='test', user=user)

更详细文档之后进行补充
详情可参考app目录下示例

api-server-flask's People

Contributors

pineapplebin avatar

Watchers

 avatar  avatar  avatar

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.