HNGX - Person API

Overview

A simple API with basic CRUD (Create, Read, Update, Delete) operations for managing a 'person' resource.

Table of Contents

Features

  • 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.

Getting Started

Ensure you have Python version 3.9.2 or above installed.

Setup

  1. Create a virtual environment:

    pip -m venv env
  2. Start the virtual environment:

    source ./env/bin/activate
  3. Clone this repository inside the folder with the virtual environment:

    git clone https://github.com/mashm3ll0w/hngx_stage_1
  4. Change to the project directory:

    cd hngx_stage_1
  5. Install the required dependencies:

    pip install -r requirements.txt
  6. 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
  7. Start the server:

    gunicorn stage_1.wsgi:application

Usage

Endpoints

  • 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.

Example Usage

Fetch All Persons

To retrieve a list of all persons, make a GET request to the following endpoint:

GET /api/

Fetch a Specific Person

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

Creating a new Person

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" }

Updating a Person's Data

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" }

Delete a Person

To delete a person, make a DELETE request to the following endpoint:

DELETE /api/id

Source Code

Github Repo