Problem Statement
Create an address book application where API users can create, update and delete addresses.
The address should:
- contain the coordinates of the address.
- be saved to an SQLite database.
- be validated
API Users should also be able to retrieve the addresses that are within a given distance and location coordinates.
Important : The application does not need a GUI. (Built-in FastAPI’s Swagger Doc is sufficient)
Note:
Latitude:
North: Positive values (0 to +90 degrees).
South: Negative values (0 to -90 degrees).
Longitude:
East: Positive values (0 to +180 degrees).
West: Negative values (0 to -180 degrees).
-
Clone or download the repository on your machine
-
Create a virtual environment
Creating virtual environment is important to ensure that all the necessary libraries can be installed there to run a specific project
python -m venv <virtual_environment_name>
-
Activate virtual environment with the following command in the terminal
<virtual_environment_name>\Scripts\activate
-
Install all the dependencies from requirements.txt file
pip install -r requirements.txt
-
Go inside the app directory and execute FastAPI application - main.py
uvicorn main:app
-
On success go to the link in the terminal {for me it is http://127.0.0.1:8000}
-
To Open Swagger application add "/docs" to the link and search on any search engine
You should able to see the below page with apis
- There are 4 apis: i. addAddress ii. addresses/{address_id} iii. deleteAddress/{address_id} iv. getAddressesByDistance
To execute apis
-
Expand the api
-
Click on Try it out to execute the api then provide the details
It is a POST method to insert the new address with coordinates to the table in the database
Provide these details and execute it
On Successful execution:
If there are some input datatype missmatch or incorrect coordinates it will throw the respective errors:
It is a PUT method to update the existing address in the table
It is a DELETE method to delete the existing address from the table
If there are no records with the given id then response will be:
"Address id not found"
This is a POST method which will give the addresses within the range of given latitude and longitude with the provided distance
If there are no records it will give:
"No addresses found in the given range!"