Skip to content

suleyunus/products-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Products API

This is an API built using djangorestframework that allows only an admin user to create, update and delete products, while allowing anyone to view available products.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installing

  • Clone the repo to your local machine
git clone https://github.com/suleyunus/products-api.git
  • cd into the project
cd products-api
  • Activate the virtual environment. Check this link on how to activate a virtual environment depending on your OS
  • Install dependencies
pip install -r requirements.txt
  • Create Database
python manage.py migrate
  • Create Admin(superuser)
python manage.py createsuperuser
  • Run the server
python manage.py runserver

Available Endpoints

  • POST /api/v1/authtoken/ Generate an auth token

Request body:

{
    "username": "your_admin_username",
    "password": "your_admin_password"
}

Response:

{
    "token": "generated_token"
}
  • POST /api/v1/products/ Create a product, requires authorisation

Request body:

{
    "name": "name_of_product",
    "description:: "description_of_product",
    "price": "product_price"
}

Headers:

Authorization: Token your_generated_token
  • PUT /api/v1/products/{id} Update a product by ID, requires authorisation

Request body:

{
    "name": "new_name_of_product",
    "description:: "new_description_of_product",
    "price": "new_product_price"
}

Headers:

Authorization: Token your_generated_token
  • DELETE /api/v1/products/{id} Delete product by ID, requires authorisation

Headers:

Authorization: Token your_generated_token
  • GET /api/v1/products Get all products
  • GET /api/v1/products/{id} Get product by ID

Built With

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages