Page MenuHomeVyOS Platform

HTTP API: move to FastAPI as web framework
Closed, ResolvedPublic


In order to support further development, ease of maintenance, and OpenAPI 3.*, we are moving to the FastAPI framework. FastAPI is based on Starlette (high performance ASGI framework) and Pydantic (validation through type hints), all in active development. The HTTP API will remain backwards compatible.


Difficulty level
Unknown (require assessment)
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible

Event Timeline

jestabro changed the task status from Open to In progress.Mar 16 2021, 4:53 PM
jestabro triaged this task as Normal priority.
jestabro created this task.
jestabro created this object in space S1 VyOS Public.

There are two versions that have been developed, reasonably feature complete, pending testing. One presents an OpenAPI schema of application/x-www-form-urlencoded (multipart forms); the other, application/json. The latter uses middleware (strictly speaking, a custom request and route class, instead of the Starlette middleware capability, although that may change) to intercept multipart requests, so as to remain backwards compatible.

Pending completion/confirmation of the compatibility layer, the latter version will be considered.

jestabro changed the task status from In progress to Needs testing.Mar 17 2021, 9:20 PM

Draft PR linked below; it is a draft pending the addition of a supporting package (vyos-http-api-tools). All data validation for application/json requests is done implicitly using Pydantic models/validators; for multipart forms requests, all explicit validation has been moved out of the endpoint function bodies and into the middleware --- this is a pedantic block of code, but allows consolidation and review of all manual checks. An OpenAPI 3.0.2 schema is automatically generated and presented at server-name/docs (Swagger) and server-name/redoc (ReDoc version; slightly more pleasing to the eye).