Table of Contents
The Person REST API Project is a simple API that provides CRUD (Create, Read, Update, Delete) operations for managing information about individuals. This project demonstrates how to develop a REST API using Django and Django REST framework, allowing you to interact with a PostgreSQL database to create, retrieve, update, and delete person records.
- Create: Add new person records with their name.
- Read: Fetch details of a person by their unique ID or name.
- Update: Modify the details of an existing person.
- Delete: Remove a person from the database.
- Dynamic Parameter Handling: Perform operations on persons by specifying their name.
- Input Validation: Ensures that the "name" field only accepts string values.
- Django: A high-level Python web framework.
- Django REST framework: A powerful and flexible toolkit for building RESTful Web APIs.
- PostgreSQL: A popular open-source relational database.
- Gunicorn: A production-ready WSGI HTTP server.
- Render: A cloud platform for hosting web applications.
- Clone the repository:
https://github.com/BrodaOJ56/HNG_INTERNSHIP_CRUD_API.git
- Create and activate a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate
- Install the dependencies:
pip install -r requirements.txt
- Set up the database:
- Create a PostgreSQL database.
- Update the database configuration in the setting.py file(Person_api).
- Start the development server using
python manage.py runserver
- Access the API in your web browser or using tools like Postman:
- On local
http://127.0.0.1:8000/api
- On live Server
https://hngperson.onrender.com/api/
- GET /api: Retrieve a list of all persons.
- GET /api/{id}: Retrieve details of a person by their ID.
- GET /api/?name={name}: Retrieve details of a person by their name.
- POST /api: Create a new person record.
- PUT /api/{id}: Update details of an existing person by their ID.
- DELETE /api/{id}: Delete a person by their ID.
Person is primary model with two attributes: id (primary key) and name (str).
+--------------------------+ | Person | +--------------------------+ | - id: int (PK) | | - name: str | +--------------------------+ | | +--------------------------+
The Person class performs CRUD methods: create(POST), read(GET), update(PUT) and delete(DELETE). These methods represent the basic CRUD operations one can perform on a Person resource.
+-------------------------+ | | | + create(POST) | | + read(GET) | | + update(PUT) | | + delete(DELETE) | | | +-------------------------+
Contributions to the project are welcome, and users are encouraged to report any issues or provide suggestions for improvement. The project is open-source and licensed under the MIT License, allowing for further development and customization.
OLUBUNMI OLUWATOBI JAMES - @ItzOfficialOJ