An CRUD contact API built on Fast API with a SQLite database using SQLAlchemy.
Go to the project directory
> contact_fastapi/backend
Install dependencies
> pipenv install
Start the virtual enviroment
> pipenv shell
Create the databse
This will give you an sqlite database consisting of 10 enteries
> python create_db.py
Start the server
> uvicorn main:app --reload
This will start the server so you can test the API at localhost:8000
Documentation will be located at localhost:8000/redocs
once the server is up and running. But for when it's not here is a breif overview.
The CREATE
endpoint will allow you to send JSON creating a new contact
localhost:8000/create-contact
Sending JSON
in the message body like so below will create a new conact:
{
"first_name": "Frank",
"last_name": "Flintstone",
"company": "Slate Rock and Gravel Company",
"tel": "210-555-1212",
"email": "[email protected]",
"address": "1 Yabba-Dabba-Doo, Bedrock, TX 12345"
}
There are two READ
endpoints they are:
localhost:8000/all-contacts
This will return all the current contacts within the database
localhost:8000/get-contact/{contact_id}
This will return a contact by its ID
The UPDATE
endpoint is similar to the create endpoint. This allows you to change contact information by contact_id
localhost:8000/update-contact/{contact_id}
{
"first_name": "Wilma",
"last_name": "Flintstone",
"company": "NULL",
"tel": "210-555-6969",
"email": "[email protected]",
"address": "1 Yabba-Dabba-Doo, Bedrock, TX 12345"
}
The DELETE
endpoint allows you to delete a contact entry via it's ID
localhost:8000/delete-contact/{contact_id}