3 ms·
I recently used Starlette, which FastAPI also uses, for a project and absolutely loved it. I went with Starlette over FastAPI because I didn't need a lot of wha
by hangonhn 6y ago
I recently used Starlette, which FastAPI also uses, for a project and absolutely loved it. I went with Starlette over FastAPI because I didn't need a lot of what FastAPI provided for that particular project.
I want to start nudging my coworkers into using FastAPI over Flask because some of the async APIs they've started using. FastAPI seems to come with all the things they want out of the box instead of adding a bunch of individual Flask packages.
Just for my own understanding, where would FastAPI be appropriate vs. Starlette and vice versa.
Thanks!
- lemagedurage 6y agoThe big additions of FastAPI is their pydantic integration which allows for input validation, and their openapi.json generation, which allows for interactive API docs of your web app out of the box. Additionally they provide docs and infrastructure for some extras you might want like authentication and testing.
- BerislavLopac 6y agoYou might like my own little tool based off of Starlette: https://pyotr.readthedocs.io https://pyotr.readthedocs.io ;)
- hangonhn 6y agoThanks! I'll take a look. Much appreciated!
- holler 6y agoI too recently started using Starlette for https://sqwok.im https://sqwok.im and had investigated FastAPI & Responder. Both look promising but I've found that Starlette on it's own is very lightweight, well-designed, and straightforward to work with (coming from many years of flask/django). Some nice features of FastAPI are the automatic response type handling, e.g. "return {'json': 'yes'}" vs "return JSONResponse({})", and the flask-like route decorators. I ended up building the former manually into my project. Both Starlette and FastAPI are worth checking out, especially if you've spent time building python web apis with django or flask in the past.
- ytjohn 6y agoI may have done something wrong, but I remember that when I would do 'return {"json": "yes"}', it would not set the content-type to json. When I discovered this, I had to go back through a bunch of code and convert it to either fastaspi.Response or JSONResponse. Creating the Response instance proved to be a better approach, because it makes it much easier to set content type, status codes, cookies, headers, etc. Again - I might have done something wrong, but if you have an instance just doing 'return {"key": "value"}', check it with curl or browser dev tools to see what the Content-Type is.