Fastapi: custome url prefix for the API instead of "/"

Created on 8 Jun 2020  路  4Comments  路  Source: tiangolo/fastapi

HI, I want to change the base context of the API from "/" to "/myownapi" please let me know how can I do it.

in the flask, I do something like this

from flask import Blueprint, url_for
from flask_restplus import Api
from configuration import config
from configuration.logger import debug, error, warning

blueprint = Blueprint('sentiment', __name__, url_prefix='/myownapi', template_folder='templates')

question

Most helpful comment

If you want to mount an entire application under a path I believe you need to make it a sub application like in https://fastapi.tiangolo.com/advanced/sub-applications-proxy/ .

This link is broken (as at Dec 2020) - try https://fastapi.tiangolo.com/advanced/behind-a-proxy/

All 4 comments

The equivalent of Flask Blueprints are Routers, check out https://fastapi.tiangolo.com/tutorial/bigger-applications/ for more info.

If you want to mount an entire application under a path I believe you need to make it a sub application like in https://fastapi.tiangolo.com/advanced/sub-applications-proxy/ .

Hopefully one of those gets you what you need!

Thanks, I am looking for the sub-application proxy option

Thanks for the help here @dbanty ! :clap: :bow:

Thanks for reporting back and closing the issue @Bhanu88 :+1:

If you want to mount an entire application under a path I believe you need to make it a sub application like in https://fastapi.tiangolo.com/advanced/sub-applications-proxy/ .

This link is broken (as at Dec 2020) - try https://fastapi.tiangolo.com/advanced/behind-a-proxy/

Was this page helpful?
0 / 5 - 0 ratings