Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See: #13324 and #11915 for more information
FastAPI POC
This is a POC of using FastAPI to replace Flask in Frigate HTTP API. It is using the defaults provided by FastAPI (uvicorn and starlette). This was discussed here and previous PR was made.
I'm proposing that we start moving to FastAPI by mounting Flask as a sub-application sub-application + 2. This means that the entire application still works as is and we can then start moving endpoint by endpoint to FastAPI until we get to a point where all endpoints are converted. At that point, we can remove Flask altogether.
I've started the conversion of 2-3 endpoints to showcase how it works:
/preview/{camera_name}/start/{start_ts}/end/{end_ts}
/preview/{camera_name}/start/{start_ts}/end/{end_ts}/frames
/{camera_name}/latest.{extension}
-> See warning below/
-> Health/config/schema.json
/logs/{service}
Here it is working with FastAPI
converted_file.mp4
HTTP API Documentation
Details
Without any extra effort, the swagger documentation is available at
http://localhost:5001/docs
orhttp://localhost:5001/redoc
See documentationconverted_file.mp4
The JSON/YAML schema can then be used to feed the HTTP API page without any human interaction.
From this documentation we can quickly create a client to be used by the front end. This can be done automatically with openapi-generator-cli. I've used this successfully multiple times at work and also for personal projects, e.g., Frigate HTTP API + 2.
Problems faced
Caution
I've faced a problem with the existing endpoints with an extension suffix:⚠️ This lines in
.(jpg|jpeg|png|webp|gif)
.As a resultnginx.conf
was commented out. I've left a comment explaining the errors. If someone wants/can help me figure out why it is failing, then use my branch to debug the endpoints that contain an extension.I've already ported all media-related endpoints in this branch and also as a PR ready to target this current PR. If somebody wants to test the problem with the endpoint terminated with those extensions use the mentioned branch.