A simple API with basic CRUD (Create, Read, Update, Delete) operations for managing a 'person' resource.
- Create a new person record using a name.
- Retrieve a list of all persons or a specific person.
- Update the details of an existing person.
- Delete a person entry from the database.
Ensure you have Python version 3.9.2 or above installed.
-
Create a virtual environment:
pip -m venv env
-
Start the virtual environment:
source ./env/bin/activate
-
Clone this repository inside the folder with the virtual environment:
git clone https://github.com/mashm3ll0w/hngx_stage_1
-
Change to the project directory:
cd hngx_stage_1
-
Install the required dependencies:
pip install -r requirements.txt
-
Create an
.env
file to hold your secrets (Please change the SECRET_KEY):echo "SECRET_KEY="0197320918cn09831c908n9023u4hc918-7918-4t791-4398v659"\nDEBUG=True\nALLOWED_HOSTS=['*']" > .env
-
Start the server:
gunicorn stage_1.wsgi:application
- GET /api Retrieve a list of all persons.
- GET /api/name Retrieve details of a specific person by name.
- POST /api Create a new person record.
- PUT/PATCH /api/id Update the details of a specific person.
- DELETE /api/id Delete a person record.
To retrieve a list of all persons, make a GET request to the following endpoint:
GET /api/
To retrieve details of a specific person by their name, make a GET request to the following endpoint, replacing :name
with the person's name:
GET /api/:name
To create a new person record, make a POST request to the following endpoint:
POST /api/
Set the Content-Type
header to application/json
, and include the person's information (name only) in the request body in JSON format, like this:
{ "name": "John Jameson" }
To update an existing person data record, make a PATCH/PUT request to the following endpoint:
PUT /api/id
Include the new person's name in the request body in JSON format, like the one below and also set the Content-Type
header to application/json
.
{ "name": "Monkey D Luffey" }
To delete a person, make a DELETE request to the following endpoint:
DELETE /api/id