Skip to content

Build a FastAPI address book API for CRUD operations on SQLite-stored addresses, including validation, coordinate tracking, and proximity-based retrieval, without a GUI.

Notifications You must be signed in to change notification settings

DataRish/FastAPI-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)


Step by Step Solution


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).


  1. Clone or download the repository on your machine

  2. 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>
    
  3. Activate virtual environment with the following command in the terminal

    <virtual_environment_name>\Scripts\activate   
    
  4. Install all the dependencies from requirements.txt file

    pip install -r requirements.txt 
    
  5. Go inside the app directory and execute FastAPI application - main.py

    uvicorn main:app
    
  6. On success go to the link in the terminal {for me it is http://127.0.0.1:8000}

    image

  7. To Open Swagger application add "/docs" to the link and search on any search engine

    http://127.0.0.1:8000/docs

You should able to see the below page with apis

image

  1. 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

addAddress

It is a POST method to insert the new address with coordinates to the table in the database

Provide these details and execute it

image

On Successful execution:

image

If there are some input datatype missmatch or incorrect coordinates it will throw the respective errors:

image

image

addresses/{address_id}

It is a PUT method to update the existing address in the table

image

image

deleteAddress/{address_id}

It is a DELETE method to delete the existing address from the table

image

If there are no records with the given id then response will be:

"Address id not found"

image

getAddressesByDistance

This is a POST method which will give the addresses within the range of given latitude and longitude with the provided distance

image

image

If there are no records it will give:

"No addresses found in the given range!"

image

About

Build a FastAPI address book API for CRUD operations on SQLite-stored addresses, including validation, coordinate tracking, and proximity-based retrieval, without a GUI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages