python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

How to user restx with blueprint #607

Open engFelipeMonteiro opened 1 month ago

engFelipeMonteiro commented 1 month ago

In the restx docs it says that can be used with flask blueprint, but I can't reproduce

How to do this, without rewriting the flasks endpoints?

Code

from flask import Flask, Blueprint
from flask_restx import Api
import logging

logger = logging.getLogger(__name__)
app = Flask(__name__)

def initialize_app(app):
    app.config['RESTX_VALIDATE'] = True
    app.register_blueprint(get_api(logger, app), url_prefix='/open')

    return app

def get_api(logger, app):
    open_bp = Blueprint('open', __name__)

    @open_bp.route('/hello')
    def hello():
        return 'Hello World'

    api = Api( 
                open_bp,
                version='0.1',
                title='webserver hello',
                description='',
                doc='/doc/',
                url_scheme='http'
    )

    #api.init_app(open_bp)
    return open_bp

def run():
    return initialize_app(app)

Expected Behavior

I would like to use a api made on flask blueprint into restx

Environment

peter-doggart commented 1 month ago

There is an example file for flask-restx with blueprints here: https://github.com/python-restx/flask-restx/blob/master/examples/todo_blueprint.py

If you are having problems, if you could give us a few more details of what your setup looks like or errors you are getting, be happy to help.