A simple CRUD (Create, Read, Update, Delete) REST API built with Django for managing user data.
- Create, read, update, and delete user records.
- RESTful API design for easy integration with front-end applications.
- Detailed documentation of API endpoints.
Before you begin, ensure you have met the following requirements:
- Python 3.5 and above installed.
- Django 3.2 and above installed.
- djangorestframework 3.14.x installed
-
Clone the repository:
git clone https://github.com/Authur-p/Hng_Stage2.git
-
Navigate to the project directory:
cd Hng_Stage2
-
Install project dependencies:
pip install -r requirements.txt
-
Create a database migrations:
python manage.py makemigrations python manage.py migrate
-
Start the development server:
python manage.py runserver
-
Access the API at
http://127.0.0.1:8000/api/
GET /api
: Retrieve a list of all users.GET /api/{name}
: Retrieve details of a specific user, through the name.POST /api
: Create a new user.PUT /api/{name}
: Update an existing user.DELETE /api/{name}
: Delete an existing user.
POST /api
Content-Type: application/json
{
"name": "newuser"
}
- Response:
{
"id": 1,
"name": "newuser"
}
GET /api
- Response:
[
{
"id": 1,
"name": "newuser"
},
{
"id": 2,
"name": "user2"
}
]
GET /api/{name}
- Response:
{
"id": 1,
"name": "newuser"
}
PUT /api/{name}
{
"name": "newuser-updated"
}
- Response:
{
"id": 1,
"name": "newuser-updated"
}
DELETE /api/{name}
{
"id": 1,
"name": "newuser-updated"
}
- Response:
204 No Content
- If the provided ID does not exist, you will receive a
404 Not Found
response. - If there is an internal server error, you will receive a
500 Internal Server Error
response.
- To run test, djangorestframework, which was installed, provides a web based means of testing all endpoints.
- Also, using Postman is also a great way of testing all the endpoints.