Skip to content

REST API Documentation

Tejasri Dontham edited this page Apr 2, 2022 · 3 revisions

Table of Contents

API Documentation

Login

Target URL

"localhost:3000" + "/#"

Request

Method: POST

Example

{
   "username" : "myUserName",
   "password" : "myPASSW1234!"
}

Fields

Elements Descriptions Type Required
username The username cannot be empty String true
password The password cannot be empty String true

Response

{ "result": "login success" } Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Register

Target URL

"localhost:3000" + "/register"

Request

Method: POST

Example

{
   "username" : "myUserName",
   "password" : "myPASSW1234!"
}

Fields

Elements Descriptions Type Required
username The username cannot be empty String true
password The password cannot be empty String true

Response

{ "result": "registration success" } Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Create Post

Target URL

"localhost:3000" + "/create"

Request

Method: POST

Example

{
    "name":"Laptop Stand",
    "description": "Useful to put laptop in a height and at a distance.",
    "location": "4000 SW 34th St Block #733C",
    "dimensions": "5 x 2 x 6 m",
    "weight":10,
    "age": 1,
    "count": 2
}

Fields

Elements Descriptions Type Required
name Name of the product String true
description Description of the item String true
location Location to pickup the item String true
dimensions Dimensions of the item String true
weight Weight of the item int true
age Age of the item int true
count No pof items int true

Response

{ "result": "post creation success" } Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Edit post

Target URL

"localhost:3000" + "/update/<post_id>"

Request

Method: PATCH

Example

{
    "name":"Steel Laptop Stand",
    "weight": 11,
    "count": 1
}

Fields

Same as create post fields. Eg: { "name":"Steel Laptop Stand", "weight": 11, "count": 1 }

Response

{ "ID": 5, "CreatedAt": "2022-02-04T20:42:18.1731823-05:00", "UpdatedAt": "2022-02-04T20:47:02.5941861-05:00", "DeletedAt": null, "name": "Steel Laptop Stand", "description": "Useful to put laptop in a height and at a distance.", "location": "4000 SW 34th St Block #733C", "dimensions": "5 x 2 x 6 m", "weight": 11, "age": 1, "count": 1 } Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Delete post

Target URL

"localhost:3000" + "/delete/<post_id>"

Request

Method: DELETE

Example

localhost:8080/delete/5

Response

{ "ID": 5, "CreatedAt": "2022-02-04T20:42:18.1731823-05:00", "UpdatedAt": "2022-02-04T20:47:02.5941861-05:00", "DeletedAt": null, "name": "Steel Laptop Stand", "description": "Useful to put laptop in a height and at a distance.", "location": "4000 SW 34th St Block #733C", "dimensions": "5 x 2 x 6 m", "weight": 11, "age": 1, "count": 1 } Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Get posts

Target URL

"localhost:3000" + "/read"

Request

Method: GET

Example

localhost:8080/read

Response

Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

Place Order

Status Codes

  • While placing orders initially we keep it in pending state and then we move it to confirmed state.
  • Once we delete we move status as cancelled state
  PENDING               status = 0
  CONFIRMED             status = 1
  CANCELLED             status = 2

Target URL

"localhost:8080" + "/placeOrder"

Request

Method: POST

Example

Request

localhost:8080/placeOrder

Body :{ "posts":[ { "count": 1, "productId": 2 }, { "count": 2, "productId": 3 } ] }

Response

{
   "orderId": 8,
   "result": "order successfully placed!"
}

Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

GIF

placeOrder

View All Orders Of All Users

Target URL

"localhost:8080" + "/allorders"

Request

Method: GET

Example

Request

localhost:8080/allOrders

  • This API is for sellers to view all the orders.

Response

{
   "Page": 1,
   "TotalPages": 1,
   "Orders": [
       {
           "ID": 1,
           "CreatedAt": "2022-04-01T17:22:12.7615198-04:00",
           "UpdatedAt": "2022-04-01T17:22:12.7615198-04:00",
           "DeletedAt": null,
           "posts": [],
           "Status": 1
       },
       {
           "ID": 2,
           "CreatedAt": "2022-04-01T17:29:50.5213792-04:00",
           "UpdatedAt": "2022-04-01T17:29:50.5213792-04:00",
           "DeletedAt": null,
           "posts": [
               {
                   "count": 1,
                   "productId": 1
               }
           ],
           "Status": 1
       },
       {
           "ID": 3,
           "CreatedAt": "2022-04-01T17:35:38.8661683-04:00",
           "UpdatedAt": "2022-04-01T17:35:38.8661683-04:00",
           "DeletedAt": null,
           "posts": [
               {
                   "count": 1,
                   "productId": 1
               }
           ],
           "Status": 1
       },
      
   ]
}

Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

GIF

GetAllOrders

View Particular Order

Target URL

"localhost:8080" + "/order/:orderId"

Request

Method: GET

Example

Request

localhost:8080/order/5

Response

{
   "ID": 5,
   "CreatedAt": "2022-04-01T17:41:37.7922598-04:00",
   "UpdatedAt": "2022-04-01T17:41:37.7922598-04:00",
   "DeletedAt": null,
   "posts": [
       {
           "count": 1,
           "productId": 1
       }
   ],
   "Status": 1
}

Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

GIF

GetOrderByOrderId

Cancel Order

Target URL

"localhost:8080" + "/cancelOrder/:OrderId"

It take the user id from the session.

Request

Method: GET

Example

Request

localhost:8080/cancelOrder/3

Response

{
   "ID": 3,
   "CreatedAt": "2022-04-01T17:35:38.8661683-04:00",
   "UpdatedAt": "2022-04-01T21:08:07.3701319-04:00",
   "DeletedAt": null,
   "posts": [
       {
           "count": 1,
           "productId": 1
       }
   ],
   "Status": 2
}
  • Status is updated to 2 - Which means order is cancelled. Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

GIF

CancelOrder

View all Order of the particular user

Target URL

"localhost:8080" + "/orders"

It takes the user id from the session.

Request

Method: GET

Example

Request

localhost:8080/orders

Response

{
   "ID": 3,
   "CreatedAt": "2022-04-01T17:41:37.7922598-04:00",
   "UpdatedAt": "2022-04-01T17:41:37.7922598-04:00",
   "DeletedAt": null,
   "posts": [
       {
           "count": 1,
           "productId": 1
       }
   ],
   "Status": 1
}

Possible status: 200, 400, 401

Message format: json

Example

Code: 200 OK

GIF

GetOrdersByUser