SairamNagothu / ProductRESTAPI

Creating more lightweight APIs..

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Product REST API

Product REST API is an micorservice related to Product based REST appplication and implemeneted using Java Spring Boot for integarting with other systems/applications. This API has the following operations,

List of APIs

1. Create Product (POST /Products)
2. Get Products (GET /Products)
3. Get Product by ProductId (GET /Products/{productId})
4. Update Product (PUT /Products/{productId})
5. Delete Product (Delete /Products/{productId})

API Reference

Create Product

To create product in the system

  POST /products

Headers

Parameter Type Description
authorization string Optional. authorization Credentials like Client Id and Client Secret
X-Correlation-Id string Optional. 16 didgits UUID
content-type string Required. Application/json

Sample Request Body

{
   "id": 1000,
   "name": "Dell model 1",
   "category": "Dell",
   "status": "Active",
   "price": 27000.0,
   "quantity": 2
}

Sample Success Response

StatusCode as 200
Product Created Successfully

Get All Products

To retrieve all products from the system.

  GET /products
Parameter Type Description
authorization string Optional. authorization Credentials like Client Id and Client Secret
X-Correlation-Id string Optional. 16 didgits UUID

Sample Response

Statuscode as 200
[
    {
        "id": 1000,
        "name": "Dell model 1",
        "category": "Dell",
        "status": "Active",
        "price": 27000.0,
        "quantity": 2
    },
    {
        "id": 1001,
        "name": "Dell model 1",
        "category": "Dell",
        "status": "Active",
        "price": 27000.0,
        "quantity": 2
    }
]

Get Products by Id

To retrive product details based on Product Id

  GET /products/${productId}
Parameter Type Description
productId string Required. Product Id to fetch respective Product details

Sample Response

Statuscode as 200
{
    "id": 1000,
    "name": "Dell model 1",
    "category": "Dell",
    "status": "Active",
    "price": 27000.0,
    "quantity": 2
    }

Error Response If product Not Found

StatusCode as 404
{
  "errorType": "404 NOT_FOUND",
  "errorCode": "404",
  "errorMessage": "Product Not Found"
}

Update Product by Id

To update product details based on Product Id

  PUT /products/${productId}
Parameter Type Description
productId string Required. Product Id to fetch respective Product details

Sample Request Body,

{
   "name": "Iphone X",
   "category": "Iphone",
   "status": "Active",
   "price": 37000.0,
   "quantity": 5
  }

Sample Response

Statuscode as 200
{
    "id": 1000,
	"name": "Iphone X",
   "category": "Iphone",
   "status": "Active",
   "price": 37000.0,
   "quantity": 5
    }

Error Response If product Not Found

StatusCode as 404
{
  "errorType": "404 NOT_FOUND",
  "errorCode": "404",
  "errorMessage": "Product Not Found"
}

Delete Product by Id

To delete a product from the system based on Product Id

  DELETE /products/${productId}
Parameter Type Description
productId string Required. Product Id to fetch respective Product details

Sample Response

Statuscode as 200
Product deleted Successfully

Error Response If product Not Found

StatusCode as 404
{
  "errorType": "404 NOT_FOUND",
  "errorCode": "404",
  "errorMessage": "Product Not Found"
}

Tech stack

Client: Java and Spring Boot Server: Tomcat

Deployment

To complile this project run

  gradle clean build

To deploy this project run

  java -jar <snapshot-name>.jar

image

Screenshots

Beloe are the local run screenshots for reference Create Product image Get Products image Get Product By Id image Get Product By Id if not found image Update Product by Id image Delete Product by Id image

About

Creating more lightweight APIs..


Languages

Language:Java 100.0%