Ejemplo n.º 1
0
        'header',
        'name':
        'Authorization',
        'description':
        "Type in the *'Value'* input box below: **'Bearer <JWT>'**, where JWT is the token"
    }
}
app = Flask(__name__)
api = Api(app=app,
          authorizations=authorizations,
          description='DevOps APIs',
          title="DevOps APIs")

SWAGGER_URL = '/swagger'
API_URL = '/swagger.json'
name_space = api.namespace('auth', description='Auth APIs')

swaggerui_blueprint = get_swaggerui_blueprint(SWAGGER_URL,
                                              API_URL,
                                              config={"app-name": "Test"})

app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@mysql/flask_api'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'some-secret-string'

db = SQLAlchemy(app)


@app.before_first_request
Ejemplo n.º 2
0
from flask import Flask, request
from flask_restful import Resource, Api
from Recuperation import CreateDB, GeAttributAndType
app = Flask(__name__)
api = Api(app=app)
ns_books = api.namespace('db', description="Books operations")
ns_movies = api.namespace('movies', description="Movies operations")


@ns_books.route("/")
class BooksList(Resource):
    def get(self):
        """
        returns a list of books
        """
        return GeAttributAndType("Teste.json", "Awa")

    def post(self):
        """
        Add a new book to the list
        """


@ns_books.route("/<string:title>")
class Book(Resource):
    def put(self, title):
        """
        Edits a selected book
        """
        CreateDB(title)
        return "Creation de la base de données reussit"
Ejemplo n.º 3
0
def initialize_app(flask_app):
    configure_app(flask_app)

    blueprint = Blueprint('api', __name__, url_prefix='/api')
    api.init_app(blueprint)
    api.add_namespace(blog_posts_namespace)
    api.add_namespace(blog_categories_namespace)
    flask_app.register_blueprint(blueprint)

    db.init_app(flask_app)


app = Flask(__name__)  #  Create a Flask WSGI application
api = Api(app)
ns = api.namespace('blog/categories',
                   description='Operations related to blog categories')


@ns.route('/')
class CategoryCollection(Resource):
    def get(self):
        """Returns list of blog categories."""
        return get_all_categories()

    @api.response(201, 'Category successfully created.')
    def post(self):
        """Creates a new blog category."""
        create_category(request.json)
        return None, 201

Ejemplo n.º 4
0
    def base_path(self):
        return ''


######################################################################
# Configure Swagger before initilaizing it
######################################################################
apii = Api(app,
           version='3.0.0',
           title='Customer REST API Service ',
           description='This is a customer server.',
           doc='/apidocs/index.html')

# This namespace is the start of the path i.e., /cutomers
ns = apii.namespace('Customers',
                    default=None,
                    description='Customer operations')
apii.namespaces.pop(0)

# Define the model so that the docs reflect what can be sent
Customer_model = apii.model(
    'Customer', {
        '_id':
        fields.String(
            readOnly=True,
            description='The unique id assigned internally by service'),
        'first_name':
        fields.String(required=True,
                      description='The first name of a Customer'),
        'last_name':
        fields.String(required=True,