Skip to content

Nexxumm/Basic-Product-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic-Product-API

Product API A basic REST API built with Django and Django Rest Framework to perform CRUD (Create, Read, Update, Delete) operations on a collection of products.

Setup and Installation

  1. Clone the Repository Clone this project to your local machine.

git clone https://github.com/Nexxumm/Basic-Product-API cd Basic-Product-API

  1. Create a Virtual Environment It's highly recommended to use a virtual environment to manage project dependencies.

For Windows:

python -m venv .venv .venv\Scripts\activate

For macOS/Linux:

python3 -m venv .venv source .venv/bin/activate

  1. Install Dependencies Install all the required packages using the requirements.txt file.

pip install -r requirements.txt

  1. Create the .env File This project uses a .env file to manage environment variables like the SECRET_KEY.

a. Create a file named .env in the project's root directory .

b. Generate a new Django secret key by running the following command in your terminal:

python manage.py shell -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

c. Copy the generated key and add it to your .env file. It should look like this:

SECRET_KEY=your-generated-secret-key-goes-here

Running the Application

  1. Apply Database Migrations Run the migrations to create the database tables for your models.

python manage.py makemigrations python manage.py migrate

  1. Run the Development Server Start the Django development server.

python manage.py runserver

The API will now be running at http://127.0.0.1:8000/.

API Endpoints You can test the API endpoints using cURL.

  1. List Products or Create a New Product URL: /products/

Methods: GET, POST

GET - Retrieve all products

curl -X GET http://127.0.0.1:8000/products/

POST - Create a new product

curl -X POST -H "Content-Type: application/json" -d '{"name": "New Gadget", "description": "A shiny new gadget.", "price": "200"}' http://127.0.0.1:8000/products/

  1. Retrieve, Update, or Delete a Specific Product URL: /products//

Methods: GET, PUT, DELETE

GET - Retrieve a single product

curl -X GET http://127.0.0.1:8000/products/1/

PUT - Update a product

curl -X PUT -H "Content-Type: application/json" -d '{"name": "Updated Gadget", "description": "An even shinier gadget.", "price": "250"}' http://127.0.0.1:8000/products/1/

DELETE - Delete a product

curl -X DELETE http://127.0.0.1:8000/products/1/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages