navapbc / template-application-flask

Apache License 2.0
7 stars 3 forks source link

[DO NOT MERGE | PROOF OF CONCEPT] Convert the API to use FastAPI instead of APIFlask #204

Open chouinar opened 11 months ago

chouinar commented 11 months ago

This will not be merged, this is a proof-of-concept and may become its own separate repo from the flask repo (an alternative? a replacement? not sure yet).

I realize this is a massive set of changes, it may be easier to just check the code out yourself and look around instead.

Changes

Modified the API to use FastAPI rather than APIFlask

Updated Pydantic to 2.x which changes the naming on a few things like the settings classes.

Context for reviewers

This is a work-in-progress, there's a lot of TODOs that I still need to cleanup.

FastAPI docs: https://fastapi.tiangolo.com/

FastAPI is an alternative to Flask (and the many libraries built ontop of Flask like APIFlask or Connexion). It is built ontop of Starlette, and has a few noteworthy differences from Flask (from my experience of setting this up):

A few downsides I've found in my setup so far:

TODO:

Testing

Rewrote any Flask-reliant test to work with FastAPI, thankfully there were minimal changes necessary (mostly switching the test client / response formats).

You can run the API locally by doing make init run-logs - might want to nuke whatever you have locally as a lot of dependencies were updated. The swagger docs can be accessed at http://localhost:8080/docs