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

Inconsistent path behaviour with APIRouter prefix #427

Closed
captaincoordinates opened this issue Jul 22, 2022 · 3 comments
Closed

Inconsistent path behaviour with APIRouter prefix #427

captaincoordinates opened this issue Jul 22, 2022 · 3 comments

Comments

@captaincoordinates
Copy link
Contributor

The pgstac application behaves inconsistently when building response href paths if an APIRouter prefix is provided.

This repo demonstrates the problem behaviour.

The StacApi constructor supports a FastAPI APIRouter object argument. APIRouter supports a prefix string argument. For example:

api = StacApi(
    app=FastAPI(),
    settings=settings,
    extensions=extensions,
    client=CoreCrudClient(post_request_model=post_request_model),
    search_get_request_model=create_get_request_model(extensions),
    search_post_request_model=post_request_model,
    response_class=ORJSONResponse,
    middlewares=[],
    router=APIRouter(prefix="/router_prefix"),
)

The OpenAPI docs correctly include /router_prefix in all paths, but most stac-fastapi responses do not include the prefix in href paths. However, a /search response does include /router_prefix in the next and prev href paths if multiple search pages are available. See the referenced repo for steps to observe this behaviour.

The links provided by STAC API implementations are extremely valuable and place STAC APIs at Level 3 on the Richardson REST Maturity Model, however this only provides value if the paths can be trusted. I think the pgstac application, and presumably also the sqlalchemy application, would benefit from a holistic review of path handling as there are several issues identifying different problems in path logic:

@geospatial-jeff
Copy link
Collaborator

would benefit from a holistic review of path handling as there are several issues identifying different problems in path logic:.

I agree with this. I believe forwarding header support is in a good place now with #415 being merged and root_path is supported by both fastapi/uvicorn/gunicorn (https://fastapi.tiangolo.com/advanced/behind-a-proxy/#providing-the-root_path).

#429 has a working solution for the APIRouter prefixing issue by propagating the router prefix used by the core endpoints to the rest of the application but I don't think it addresses the main issue here which is that API routers are not used or exposed in a consistent manner throughout the project. For example:

Organizing routers around conformance classes is the most logical approach; all the core endpoints will use one router while all the transactions endpoints will use another etc. But this needs to be implemented consistently throughout the project for it to mean anything.

@drnextgis
Copy link
Contributor

drnextgis commented Aug 1, 2022

I don't get your comment @geospatial-jeff.

UPD: Ahh I see you mean that for those places the router cannot be overridden by a user.

@geospatial-jeff
Copy link
Collaborator

UPD: Ahh I see you mean that for those places the router cannot be overridden by a user.

Yup exactly! If the user can pass their own APIRouter wherever it is appropriate prefixing the entire app (or just a part of it) becomes very simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants