The second task for HNG Internship is to develop a REST API with Basic CRUD Operation.
Framework: FastAPI
Server: uvicorn
Databases: SQLite (local), PostgreSQL (production)
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 |
A test file "sql_test.py" has been created with tests to check. To run tests, run the following command
pytest
This API is deployed on Railway. Locally the database used is SQLite while for production it's PostgreSQL.
psycopg2-binary was installed due to the production database.
- 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)
The "person.db" database should be deleted, if you named or wish to name your database some different from "person".
If you are using a different device, lookup on how certain things are done. e.g creating a virtual environment.