Summary
In this chapter, we have created a fully functional CRUD backend application for our cars – MongoDB is connected at each startup of the app and disconnected on each shutdown, and we have this connection available in every request. We implemented simple yet functional, and, I hope, illustrative models and opted for strings as IDs in our database. It is time to create our frontend while trying to keep it equally simple.
There are many improvements and not-so-advanced features that should be implemented in this API, but I have omitted them for the sake of brevity. Pagination of results – with the use of the limit and skip operators in MongoDB implemented as query strings in FastAPI – is probably the first thing that comes to mind. FastAPI and its way of handling query strings, combined with the Motor/PyMongo way of constructing MongoDB queries as Python dictionaries, offers almost unlimited flexibility and extensibility. If you feel inclined to try things...