Creating Users Table via SQLAlchemy & FastAPI
First we will need to define our Table model in
models.py
Note: The unique=True
constraint will restrict users from registering with the same email twice
We should set up a schema for the user registration in the
schemas.py
fileWe can use the
EmailStr
validationThis requires the
email_validator
Module to be installed
This should already be installed if we have done:
Can be checked with pip freeze
Documentation and Additional info: Click here!
The schema should look something like this:
Now we will have to create a new path operation in FastAPI's
main.py
file
Once we test this via postman we should get the response like this:
These is an issue with this, we should never send the PASSWORD back to the user
We need to define a user response in
schemas.py
We also need to update our response model in
main.py
We should get a proper response now with EMAIL and ID:
YOU SHOULD NEVER STORE THE PASSWORDS IN CLEAR TEXT AS IN THIS EXAMPLE
Click here to see how to HASH Passwords
Last updated