Skip to content

Latest commit

 

History

History

backend

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

The Back End

FastAPI SQLite Code style: black

An CRUD contact API built on Fast API with a SQLite database using SQLAlchemy.

Run Locally 💻

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 📚

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.

CREATE 🦄

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"
}

READ 🤓

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

UPDATE ⤴️

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"
}

DELETE ❎

The DELETE endpoint allows you to delete a contact entry via it's ID

localhost:8000/delete-contact/{contact_id}

Acknowledgements