Git Product home page Git Product logo

route-loader-py's Introduction

RouteLoader (for Flask)

RouteLoader is an API managing tool for Flask, including:

  1. API descriptions managing
  2. Checking incoming request according to API descriptions
  3. Generating API Documents according to API descriptions

Quick Example

Notice: For a full example, please see demo.py and other related files.

# -*- coding: utf-8 -*-
try:
    # Use oyaml to keep the key orders
    import oyaml as yaml
except ImportError:
    import yaml

from flask import Flask, Blueprint, request, render_template, jsonify
from routeloader import RouteLoader

##### Init RouteLoader #####

# Load API config file
ROUTE = yaml.load("""---
app:
  index:
    showInDoc: true
    name     : Flask app index
    method   : get
    url      : "/"
    response : html
  doPost:
    showInDoc: true
    name     : Flask app POST example
    method   : post
    url      : "/do_post"
    response : json
    body:
      data:
        id:
          "$desc"      : ID
          "$isRequired": true
          "$type"      : int
          "$example"   : 1
""")

##### Use RouteLoader on Flask app object #####
# Init RouteLoader
route_loader = RouteLoader()

# Flask app object
app = Flask(__name__)

@route_loader.route(app, ROUTE['app']['index'])
def index():
    return render_template('index.html')

@route_loader.route(app, ROUTE['app']['doPost'])
def do_post():
    ret = request.get_data(as_text=True)

    return ret

##### API Documents #####
route_loader.create_doc(app, '/doc')

File list

File Type Description
routeloader.py Core RouteLoader core code (Routeloader)
objectchecker.py Core RouteLoader core code (JSON checker)
templates/api_docs.html Core RouteLoader core code (API Document template
static/* Resource API Document css/js/font Resource
route.yaml Example Route file in YAML format
demo.py Example Flask project example code
my_middlewares.py Example Example middlewares for Flask
my_decorators.py Example Example decorators for Flask
templates/_base.html Example Flask project example template (Base template)
templates/_macros.html Example Flask project example template (Macros)
templates/index.html Example Flask project example template (Flask app index template)
templates/my_module_index.html Example Flask project example template (MyModule blueprint index template)

Variable USE_CSS_JS_FONT_RESOURCE_FROM_CDN in api_doc.html

Value Description
True Default: Load css/js/font resources fron CDN
False Load css/js/font resources from static folder

Notice: You can change the URL of the resources if you have a different static file path.

route-loader-py's People

Contributors

pastgift avatar

Stargazers

 avatar

Watchers

James Cloos 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.