This django_rest API allows you to manage a collection of persons with basic CRUD (Create, Read, Update, Delete) operations. You can use this API to perform actions on person records such as adding new persons, querying persons by name, updating their information, and deleting them.
Before setting up and running the Person API, ensure you have the following prerequisites installed:
- Django
- Django rest_framework
-
Fork and clone the repository to your local machine:
git clone <repository-url> cd person-api-django django rest_framework
-
Install the project dependencies:
pip install django
To start the API server, run the following command:
python manage.py runserver
The server will start on port 8000 by default
- Endpoint:
GET /api/people
- Description: Retrieves a list of all people in the database.
- Response: 200 OK
- Endpoint:
GET /api/:user_id
- Description: Retrieves a specific person by their ID.
- Response: 200 OK or 404 Not Found
-
Endpoint:
POST /api
-
Description: Creates a new person in the database.
-
Request Body:
{ "name": "Harry Potter" }
-
Response: 201 Created or 400 Bad Request (in case of validation errors)
-
Endpoint:
PUT /api/:user_id
-
Description: Updates a person's information by their ID.
-
Request Body:
{ "name": "Updated Name" }
-
Response: 200 OK or 404 Not Found
- Endpoint:
DELETE /api/:name
- Description: Deletes a person by their ID.
- Response: 200 OK or 404 Not Found