Skip to content

ycc140/fastapi_mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI-MongoDB example

An extensive python FastAPI example using MongoDB

Author: Anders Wiklund

This code repository is an extensive FAstAPI example of a RESTful API using MongoDB.

Async IO is a vital part of FastAPI, and it will be used extensively in this example.

The root of my example is derived from an example that Arjan has shown in a YouTube video, the corresponding code is available in this GitHub repo.

This repository is structured around the Medium article parts. There's one folder per part. Each folder contains all the code you need to follow along with the examples for the corresponding part.

Here's a brief outline of the article parts

It explains the absolute basic part of the API. It is using a dictionary as a DB just to show the concepts without too much clutter that takes away focus from what is important. RESTful best practices have been followed when naming endpoints and returning the proper status codes.

This part shows how to expand the Swagger documentation within the code.

This part adds initial configuration handling using the Pydantic BaseSettings class. Project parameters in an .env file. Later on, when we add database support and Authentication passwords we will use Pydantic secrets files. In part9, we will integrate Docker secrets with Pydantic secrets.

This part adds normalized log handling with color using the third party Loguru package.

This part adds the usage of MongoDB. It also shows how to install MongoDB using Docker for local usage.

This part adds health status handling. It displays MongoDB connection status.

This part adds API-key Authentication handling. This type of Authentication should only be used together with TLS/SSL certificates so that the communication is encrypted between the browser and the API.

This part adds Mock testing of the API using the third party pytest package. The "mocking" part is the MongoDB itself. This gives us much better control and makes it a lot easier to test, for example, DB failures during create and update operations.

This part adds docker functionality with multiple environments using a multi-build Dockerfile solution to reduce container size.

About

An extensive python FastAPI example using MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published