Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Fallback to the old API for undefined routes. #14

Closed
wants to merge 1 commit into from

Conversation

jchristgit
Copy link
Member

This adds a new endpoint handler using the path converter in order to match
requests directed to any subtree. As long as this endpoint is the last to be
included in the router, all requests not matching defined routes under the
/api endpoint will be forwarded to the old API.

Two new settings are added for this. One is the endpoint of the old API to
forward to, which may change in the future due to the pending subdomain removal
pull request. The other is the API token to use for the new API authenticating
with the old API: Whilst everything else sent by the client is forwarded to the
old API, the authorization schemes between the new and old API differ.

The entire point behind this functionality is to allow us to incrementally port
over endpoints to the new API, whilst reconfiguring clients to use the new API
completely.

Closes #8.

This adds a new endpoint handler using the `path` converter in order to match
requests directed to any subtree. As long as this endpoint is the last to be
included in the router, all requests not matching defined routes under the
`/api` endpoint will be forwarded to the old API.

Two new settings are added for this. One is the endpoint of the old API to
forward to, which may change in the future due to the pending subdomain removal
pull request. The other is the API token to use for the new API authenticating
with the old API: Whilst everything else sent by the client is forwarded to the
old API, the authorization schemes between the new and old API differ.

The entire point behind this functionality is to allow us to incrementally port
over endpoints to the new API, whilst reconfiguring clients to use the new API
completely.

Closes #8.
@jchristgit jchristgit added area: back-end area: unit tests level: intermediate type: feature A request for or implementation of a new feature area: endpoint Related to an endpoint/route labels Jul 8, 2021
Copy link

@Shivansh-007 Shivansh-007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting implementation of proxying request the old api. Two small comments and rest looks good. I am not really sure about the tests if there is a better way to do the mocking.

api/main.py Show resolved Hide resolved
api/v1/router.py Show resolved Hide resolved
@Shivansh-007
Copy link

Could we possibly add the python-discord/site GHCR package to docker-compose.yml?

@jchristgit
Copy link
Member Author

Could we possibly add the python-discord/site GHCR package to docker-compose.yml?

I also thought about that, but decided against it, due to the docker initialization steps required to get the site up and running. I don't really want to duplicate postgres/init.sql across the repositories (albeit not sure if it's required in the first place), and if you have the site development set up locally, it's very straightforward to use it.

Copy link

@Shivansh-007 Shivansh-007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks :shipit:

status_code=forward_response.status_code,
)

except Exception as err:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me. Although, it might be possible that here, httpx.RequestError is better,
as FastAPI will raise the errors internally for the rest of the code.
(I'm talking about

body = await request.body()

That will raise RequestValidationError internally, in case something goes wrong.)

@jchristgit
Copy link
Member Author

Closing this per us sunsetting this project.

@jchristgit jchristgit closed this Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: back-end area: endpoint Related to an endpoint/route area: unit tests level: intermediate type: feature A request for or implementation of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluate possibility of forwarding undefined routes to another configured backend
3 participants