This application performs CRUD (Create, Read, Update, Delete) operations on a user domain. It provides a simple API to manage user records.
- Getting Started
- Prerequisites
- API Endpoints
- Request and Response Formats
- Sample API Usage
- Known Limitations or Assumptions Made During Development
This UML diagram provides an overview of the structure of our API classes and their relationships.
The ERD illustrates the database tables and their relationships in the application.
Before you begin, ensure you have met the following requirements:
-
Python: You must have Python 3.7 or higher installed. If not, you can download and install Python from the Official Python website.
-
Virtual environment (optional but recommended): It's a good practice to create a virtual environment for your project. You can create one using the built-in
venv
Follow these steps to set up and run the CRUD application:
-
Clone the repository:
git clone https://github.com/BryanNah/backend-stage-two-task
-
Navigate to the project directory:
cd backend-stage-two-task
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv # Create virtual environment source venv/bin/activate # Activate virtual environment (Linux/macOS) venv\Scripts\activate # Activate virtual environment (Windows)
-
Install the required dependencies:
pip install -r requirements.txt
-
Start the CRUD application:
uvicorn task.main:app --port 8000
The application will be accessible at http://localhost:8000.
Endpoint: /api
HTTP Method: POST
Request Body: JSON
Response: JSON
Endpoint: /api/{user_id}
HTTP Method: GET
Response: JSON
Endpoint: /api/{user_id}
HTTP Method: PUT
Request Body: JSON
Response: JSON
Endpoint: /api/{user_id}
HTTP Method: DELETE
Response: JSON
Field: name
Type: String
Field: id, Type: Integer
Field: name, Type: String
Here are some sample API requests and responses:
For information about the API Usage (https://hng-backend-task-tcnq.onrender.com/docs)
- Request
POST http://localhost:8000/api Content-Type: application/json { "name": "John Doe" }
- Response
{ "id": 1 "name": "John Doe" }
- Request
GET http://localhost:8000/api/1
- Response
{ "name": "John Doe" }
- Request
PUT http://localhost:8000/api/1 Content-Type: application/json { "name": "Nahabwe Brian" }
- Response
{ "id": 1 "name": "Nahabwe Brian" }
- Request
DELETE http://localhost:8000/api/1
- Response
{ "details": "User successfully deleted" }
1. The API assumes that the id field of a user is unique and auto-incrementing.
2. The API assumes that the name field of a user is a string.
3. The API does not perform any authentication or authorization.
4. The database used is SQLite which stores data in the file on local system.