def create_api(app):

    api  = Api(app, api_spec_url = '/api/swagger', host = '{}:{}'.format(HOST,PORT), schemes = [ "http" ] )
    # Expose the User object 
    api.expose_object(User)
    user = User(name='test',email='em@il', json = { 'test' : 'data' } )

    # Set the JSON encoder used for object to json marshalling
    app.json_encoder = SAFRSJSONEncoder
    # Register the API at /api/docs
    swaggerui_blueprint = get_swaggerui_blueprint('/api', '/api/swagger.json')
    app.register_blueprint(swaggerui_blueprint, url_prefix='/api')


    print('Starting API: http://{}:{}/api'.format(HOST,PORT))
    app.run(host=HOST, port = PORT)
Exemple #2
0
def create_api(app):

    api = Api(app,
              api_spec_url="/api/swagger",
              host="{}:{}".format(HOST, PORT),
              schemes=["http"])
    # Expose the User object
    api.expose_object(User)
    user = User(name="test", email="em@il")

    # Set the JSON encoder used for object to json marshalling
    app.json_encoder = SAFRSJSONEncoder
    # Register the API at /api/docs
    swaggerui_blueprint = get_swaggerui_blueprint("/api", "/api/swagger.json")
    app.register_blueprint(swaggerui_blueprint, url_prefix="/api")

    print("Starting API: http://{}:{}/api".format(HOST, PORT))
    app.run(host=HOST, port=PORT)
Exemple #3
0
    builtins.log = log

    with app.app_context():
        # Create a user and a book and add the book to the user.books relationship
        user = User(name="thomas", email="em@il")
        book = Book(name="test_book")
        user.books.append(book)
        db.session.add(user)
        db.session.add(book)
        db.session.commit()  # COMMIT because SAFRSBase.db_commit = False

        api = Api(app,
                  api_spec_url=API_PREFIX + "/swagger",
                  host="{}:{}".format(HOST, PORT))
        # Expose the database objects as REST API endpoints
        api.expose_object(User)
        api.expose_object(Book)
        # Set the JSON encoder used for object to json marshalling
        app.json_encoder = SAFRSJSONEncoder

        @app.route("/")
        def index():
            """Create a redirect from / to /api"""
            return """<ul><li><a href=admin>admin</a></li><li><a href=api>api</a></li>"""

        # Register the API at /api/docs
        swaggerui_blueprint = get_swaggerui_blueprint(
            API_PREFIX, API_PREFIX + "/swagger.json")
        app.register_blueprint(swaggerui_blueprint, url_prefix=API_PREFIX)
        print("Starting API: http://{}:{}{}".format(HOST, PORT, API_PREFIX))
        app.run(host=HOST, port=PORT)
Exemple #4
0
    logging.getLogger(__name__).setLevel(logging.DEBUG)
    builtins.log = log
    # prevent redirects when a trailing slash isn't present
    app.url_map.strict_slashes = False

    with app.app_context():
        # Create a user and a book and add the book to the user.books relationship
        user = User(name='thomas', email='em@il')
        book = Book(name='test_book')
        user.books.append(book)

        api = Api(app,
                  api_spec_url=API_PREFIX + '/swagger',
                  host='{}:{}'.format(HOST, PORT))
        # Expose the database objects as REST API endpoints
        api.expose_object(User)
        api.expose_object(Book)
        api.expose_object(Test)
        # Set the JSON encoder used for object to json marshalling
        app.json_encoder = SAFRSJSONEncoder

        @app.route('/')
        def goto_api():
            '''Create a redirect from / to /api'''
            return redirect(API_PREFIX)

        # Register the API at /api/docs
        swaggerui_blueprint = get_swaggerui_blueprint(
            API_PREFIX, API_PREFIX + '/swagger.json')
        app.register_blueprint(swaggerui_blueprint, url_prefix=API_PREFIX)
        print('Starting API: http://{}:{}{}'.format(HOST, PORT, API_PREFIX))