Skip to content

Authur-p/Hng_Stage2

Repository files navigation

HNG stage 2 CRUD API

Python Django License

A simple CRUD (Create, Read, Update, Delete) REST API built with Django for managing user data.

Table of Contents

Features

  • Create, read, update, and delete user records.
  • RESTful API design for easy integration with front-end applications.
  • Detailed documentation of API endpoints.

Prerequisites

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

Getting Started

  1. Clone the repository:

    git clone https://github.com/Authur-p/Hng_Stage2.git
  2. Navigate to the project directory:

    cd Hng_Stage2
  3. Install project dependencies:

    pip install -r requirements.txt
  4. Create a database migrations:

    python manage.py makemigrations
    python manage.py migrate
  5. Start the development server:

    python manage.py runserver
  6. Access the API at http://127.0.0.1:8000/api/

API Endpoints

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

Usage

Create a new user

POST /api
Content-Type: application/json

{
  "name": "newuser"
}
  • Response:
{
  "id": 1,
  "name": "newuser"
}

List of all user

GET /api
  • Response:
[
   {
     "id": 1,
     "name": "newuser"
   },
   {
     "id": 2,
     "name": "user2"
   }
]

Get a person by name

GET /api/{name}
  • Response:
{
  "id": 1,
  "name": "newuser"
}

Update an existing user

PUT /api/{name}
{
  "name": "newuser-updated"
}
  • Response:
{
  "id": 1,
  "name": "newuser-updated"
}

Delete an existing user

DELETE /api/{name}
{
   "id": 1,
  "name": "newuser-updated"
}
  • Response:
204 No Content

Error Handling

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

Testing

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages