The document gives a detailed information on how to set up the REST API for the "Person" resource. There's the set up instruction, request/response formats, sample API usage and known limitations/assumptions made. Furthermore, there's a link to a live interactive documentation.
If you choose to fork before cloning the project be sure to use the link from your own repo to clone.
Clone the project
git clone https://github.com/A3AJAGBE/person_api
Go to the project directory
cd person_api
Create virtual environment
python3 -m venv venv
Activate virtual environment
source venv/bin/activate
Install dependencies
pip install -r requirements.txt
Start the server
uvicorn main:app --reload
To run this project, you will need to create a .env file and add the environment variable to it.
DATABASE_URL
an example on how to set the variable
DATABASE_URL = "sqlite:///[INSERT DB NAME HERE].db"
POST /api
Parameter | Type | Description |
---|---|---|
name |
string |
Required |
GET /
GET /api/{user_id}
Parameter | Type | Description |
---|---|---|
id |
integer |
Required |
GET /api?name=[INSERT HERE]
Parameter | Type | Description |
---|---|---|
name |
string |
Required |
PUT /api/{user_id}
Parameter | Type | Description |
---|---|---|
id |
integer |
Required |
DELETE /api/{user_id}
Parameter | Type | Description |
---|---|---|
id |
integer |
Required |
{
"name": "joel d'souza"
}
{
"name": "Joel D'Souza",
"user_id": 1
}
{
"detail": "Name exist already"
}
{
"name": "JaneDoe-Smith!"
}
{
"detail": "Invalid name input"
}
{
"name": "Joel D'Souza",
"user_id": 1
}
{
"detail": "Person not found"
}
{
"name": "Joel D'Souza",
"user_id": 1
}
{
"detail": "Person not found"
}
{
"name": "darnarys fire"
}
{
"name": "Darnarys Fire",
"user_id": 1
}
{
"detail": "No change in the name"
}
{
"detail": "Name exist already"
}
{
"name": " DarnarysFire"
}
{
"detail": "Invalid name input"
}
{
"detail": "Person not found"
}
"Person with id number: 1 was deleted."
{
"detail": "Person with id number: 3, not found."
}
import requests
api_url = "http://127.0.0.1:8000/api"
add_person = {
"name": "jessica pier"
}
res = requests.post(api_url, json=add_person)
data = res.json()
print(data)
import requests
api_url = "http://127.0.0.1:8000/api/19"
res = requests.get(api_url)
data = res.json()
print(data)
import requests
api_url = "http://127.0.0.1:8000/api?name=jessica pier"
res = requests.get(api_url)
data = res.json()
print(data)
import requests
api_url = "http://127.0.0.1:8000/api/19"
update_person = {
"name": "jess pier"
}
res = requests.put(api_url, json=update_person)
data = res.json()
print(data)
import requests
api_url = "http://127.0.0.1:8000/api/19"
res = requests.delete(api_url)
data = res.json()
print(data)
A test file "sql_test.py" has been created with tests to check. To run tests, run the following command
pytest
Check out a live interactive documentation here. It will allow you interact/test the API with ease.
- Go to the page
- Click on the dropdown button on the right side corner of each requests (POST, GET, PUT, DELETE)
- Click on "Try it now" button, it's on the right side corner as well
- Fill the request body (if any)
- click on "Execute"
- Familiarity with Python
- Familiarity with git and GitHub
- No auth Implementation for the API
- The application was developed on MacOS
- Knowledge of using the command line interface (CLI)