Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to user restx with blueprint #607

Open
engFelipeMonteiro opened this issue Jul 9, 2024 · 1 comment
Open

How to user restx with blueprint #607

engFelipeMonteiro opened this issue Jul 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@engFelipeMonteiro
Copy link

engFelipeMonteiro commented Jul 9, 2024

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

  • Python version 3.9
  • Flask version 2.3.3
  • Werkzeug 3.0.1
  • Flask-RESTX version 1.1.0
  • Other installed Flask extensions
@engFelipeMonteiro engFelipeMonteiro added the bug Something isn't working label Jul 9, 2024
@peter-doggart
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants