Ejemplo n.º 1
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', 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    logging.getLogger(__name__).setLevel(logging.DEBUG)
    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")
Ejemplo n.º 4
0
    API_PREFIX = '/api'
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    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(
Ejemplo n.º 5
0
        api.expose_object(sclass)


HOST = sys.argv[1] if len(sys.argv) > 1 else '0.0.0.0'
PORT = 5000

ma = Marshmallow(app)

# We need some cross-module global variables to be set
__builtin__.db = db
__builtin__.log = app.logger
__builtin__.ma = ma
# Create the database

api = Api(app,
          api_spec_url='/api/swagger',
          host='{}:{}'.format(HOST, PORT),
          schemes=["http"])

expose_tables()
# Expose the objects
# 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')


@app.route('/')
def goto_api():
    return redirect('/api')
Ejemplo n.º 6
0
        api.expose_object(sclass)


HOST = sys.argv[1] if len(sys.argv) > 1 else "0.0.0.0"
PORT = 5000

ma = Marshmallow(app)

# We need some cross-module global variables to be set
__builtin__.db = db
__builtin__.log = app.logger
__builtin__.ma = ma
# Create the database

api = Api(app,
          api_spec_url="/api/swagger",
          host="{}:{}".format(HOST, PORT),
          schemes=["http"])

with app.app_context():
    expose_tables()
# Expose the objects
# 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")


@app.route("/")
def goto_api():
    return redirect("/api")
Ejemplo n.º 7
0
            mailfile.write(content)
        return {"result": "sent {}".format(content)}


HOST = sys.argv[1] if len(sys.argv) > 1 else "0.0.0.0"
PORT = 5000

# Create the database
db.create_all()

with app.app_context():
    # Create a user
    user = User(name="test", email="em@il")

    api = Api(app,
              api_spec_url="/api/swagger",
              host="{}:{}".format(HOST, PORT),
              schemes=["http"])
    # Expose the User object
    api.expose_object(User)
    # 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")

    @app.route("/")
    def goto_api():
        return redirect("/api")

    print("Starting API: http://{}:{}/api".format(HOST, PORT))
    # app.run(host=HOST, port = PORT)
Ejemplo n.º 8
0
            mailfile.write(content)
        return { 'result' : 'sent {}'.format(content)}


HOST = sys.argv[1] if len(sys.argv) > 1 else '0.0.0.0'
PORT = 5000


# Create the database
db.create_all()

with app.app_context():
    # Create a user
    user = User(name='test',email='em@il')

    api  = Api(app, api_spec_url = '/api/swagger', host = '{}:{}'.format(HOST,PORT), schemes = [ "http" ] )
    # Expose the User object 
    api.expose_object(User)
    # 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')

    @app.route('/')
    def goto_api():
        return redirect('/api')

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