How to indicate base url in Flask Restplus documentation
By default, when using this pattern (ie. with app
as constructor argument), the API is on the root endpoint (ie. /
) and the swagger documentation is on the API root (ie. still /
).
You have multiple possibilities:
Use a blueprint to change the API root
If you want to keep the documentation on the API root but change the API root, use a blueprint to register you API where you want.
from flask import Flask, Blueprint
from flask_restplus import Api
app = Flask(__name__)
blueprint = Blueprint('api', __name__, url_prefix='/test')
api = Api(blueprint)
app.register_blueprint(blueprint)
assert url_for('api.doc') == '/test/'
Only change the documentation location
If you want to keep the API root at the same place but only move the documentation location, Flask-restplus allows you to specify it with the doc
parameter.
from flask import Flask
from flask_restplus import Api
app = Flask(__name__)
api = Api(app, doc='/test/')
assert url_for('doc') == '/test/'
You can also combine both. See http://flask-restplus.readthedocs.io/en/stable/swagger.html#customization for more details on advanced documentation customization.
you could define it with prefix parameter. I've tried it on version 0.13.0.
from flask import Flask
from flask_restplus import Api
app = Flask(__name__)
api = Api(app, prefix='/api')