Skip to content

How to user restx with blueprint #607

Open
@engFelipeMonteiro

Description

@engFelipeMonteiro

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)

wsgi_app = run()

To run can do this:

python -m waitress file:wsgi_app

Expected Behavior

I would like to use a api made on flask blueprint into restx but I get this:
Image

Environment

  • Python version 3.9
  • Flask version 2.3.3
  • Werkzeug 3.0.1
  • Flask-RESTX version 1.1.0
  • Other installed Flask extensions

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions