-
Notifications
You must be signed in to change notification settings - Fork 8
Home
A simple Node E-Commerce application for testing RESTful web services.
This API will perform Health check of the App and confirm the status if it is UP and Running
http://localhost:3004/health
Status Code : 200
Body
{
"status": "UP and Running",
"uptime": "103.842424208 seconds",
"timestamp": "2024-09-08T08:53:31.956Z"
}
- If the App is not running, it will return status code 400 with
status: 'DOWN and OUT!'
alongwith the error message.
This API will allow adding new orders.
curl -X POST http://localhost:3004/addOrder \
-H "Content-Type: application/json" \
-d '{
"user_id": "12345",
"product_id": "98765",
"product_name": "Cool Gadget",
"product_amount": 100.00,
"qty": 2,
"tax_amt": 10.00,
"total_amt": 220.00
}'
[ {
"user_id": "1",
"product_id": "1",
"product_name": "iPhone",
"product_amount": 500.00,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 505.99
},
{
"user_id": "1",
"product_id": "2",
"product_name": "iPad",
"product_amount": 699.00,
"qty": 1,
"tax_amt": 7.99,
"total_amt": 706.99
},
{
"user_id": "2",
"product_id": "2",
"product_name": "iPhone 15 PRO",
"product_amount": 999.00,
"qty": 2,
"tax_amt": 9.99,
"total_amt": 1088.99
},
{
"user_id": "3",
"product_id": "3",
"product_name": "Samsung S24 Ultra",
"product_amount": 4300.00,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 4305.99
}]
Status Code : 201
Body
{
"message": "Orders added successfully!",
"orders": [
{
"id": 1,
"user_id": "1",
"product_id": "1",
"product_name": "iPhone",
"product_amount": 500,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 505.99
},
{
"id": 2,
"user_id": "1",
"product_id": "2",
"product_name": "iPad",
"product_amount": 699,
"qty": 1,
"tax_amt": 7.99,
"total_amt": 706.99
},
{
"id": 3,
"user_id": "2",
"product_id": "2",
"product_name": "iPhone 15 PRO",
"product_amount": 999,
"qty": 2,
"tax_amt": 9.99,
"total_amt": 1088.99
},
{
"id": 4,
"user_id": "3",
"product_id": "3",
"product_name": "Samsung S24 Ultra",
"product_amount": 4300,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 4305.99
}
]
}
- Request Payload should be an array of Objects else status code 400 Bad request will be shown
- Request Payload should contain the following fields mandatorily: user_id, product_id, product_name, product_amount, qty, tax_amt, and total_amt else 400 Bad request will be shown
- "Id" field should be auto incremented when an order is added
- Currently, no check is added for duplicate orders
This API will fetch all the orders available in the system.
curl -X GET http://localhost:3004/getAllOrders
This API will fetch all the available orders.
Status Code : 200
Body
{
"message": "Orders fetched successfully!",
"orders": [
{
"id": 1,
"user_id": "1",
"product_id": "1",
"product_name": "iPhone",
"product_amount": 500,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 505.99
},
{
"id": 2,
"user_id": "1",
"product_id": "2",
"product_name": "iPad",
"product_amount": 699,
"qty": 1,
"tax_amt": 7.99,
"total_amt": 706.99
},
{
"id": 3,
"user_id": "2",
"product_id": "2",
"product_name": "iPhone 15 PRO",
"product_amount": 999,
"qty": 2,
"tax_amt": 9.99,
"total_amt": 1088.99
},
{
"id": 4,
"user_id": "3",
"product_id": "3",
"product_name": "Samsung S24 Ultra",
"product_amount": 4300,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 4305.99
}
]
}
- Response should be a JSON object
- Two fields should be fetched in the response,
1. message
and2. An array of Order Objects
- Order object should contain the following fields with values
{
"id": 1,
"user_id": "1",
"product_id": "1",
"product_name": "iPhone",
"product_amount": 500,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 505.99
}
- If no records are found following response should be displayed
*** Status Code - 404 ***
{
"message": "No Order found!!"
}
This API will fetch the orders as per the Query param - id, user_id or product_id
curl -X GET "http://localhost:3004/getOrder?id=1
curl -X GET "http://localhost:3004/getOrder?user_id=1
curl -X GET "http://localhost:3004/getOrder?product_id=1
curl -X GET "http://localhost:3004/getOrder?id=1&product_id=1
Query Parameters
id
user_id
product_id
Data filtered according to the query parameter supplied in request should be returned in the response as follows:
Status Code : 200
Body
{
"message": "Order found!!",
"orders": [
{
"id": 1,
"user_id": "1",
"product_id": "1",
"product_name": "iPhone",
"product_amount": 500,
"qty": 1,
"tax_amt": 5.99,
"total_amt": 505.99
}
]
}
- Fetch the records based on
id (order id)
,product_id
,user_id
individually or clubbing all the three query parameters withAND
condition - When no records are available for the query parameter, then status code 404 should be displayed with the following message in the response: Response Body
{
"message": "No Order found with the given parameters!"
}
This API will update the order details. It requires Authentication token in the request header that could be taken using the /auth
API.
curl --location --request PUT 'http://localhost:3004/updateOrder/1' \
--header 'Content-Type: application/json' \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzI1MzU1MTM0LCJleHAiOjE3MjUzNTg3MzR9.URm8jqhNUPhXjbcDzrbWp7K9RK8boZw-4s1WTtGgnI0' \
--data '{
"user_id": "1",
"product_id": "5",
"product_name": "Samsung Galaxy S24 Ultra",
"product_amount": 14337.00,
"qty": 5,
"tax_amt": 90.00,
"total_amt": 14427.00
}'
{
"user_id": "1",
"product_id": "5",
"product_name": "Samsung Galaxy S24 Ultra",
"product_amount": 14337.00,
"qty": 5,
"tax_amt": 90.00,
"total_amt": 14427.00
}
Status Code : 200
Body
{
"message": "Order updated successfully!",
"order": {
"order_id": 1,
"user_id": "12345",
"product_id": "98765",
"product_name": "Updated Gadget",
"product_amount": 120.00,
"qty": 3,
"tax_amt": 12.00,
"total_amt": 372.00
}
}
- Request Payload should contain the following fields mandatorily:
user_id
,product_id
,product_name
,product_amount
,qty
,tax_amt
, andtotal_amt
else 400 Bad request should be displayed. - If
Order Id
does not exists, then status code 404 should be displayed with the following message :
{
"message": "Order not found!"
}
- Currently, no check is added for duplicate orders
- If Authentication token is not provided, then status code - 403 should be displayed with the following message in response:
{
"message": "Forbidden! Token is missing!",
}
- If token validation fails, then status code - 404 should be displayed with the following message in response:
{
"message": "Failed to authenticate token!",
}
This API will allow updating specific order detail. It requires Authentication token in the request header that could be taken using the /auth
API.
curl --location --request PATCH 'http://localhost:3004/partialUpdateOrder/1' \
--header 'Content-Type: application/json' \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzI1MzU1MTM0LCJleHAiOjE3MjUzNTg3MzR9.URm8jqhNUPhXjbcDzrbWp7K9RK8boZw-4s1WTtGgnI0' \
--data '{
"product_name": "iPhone 15 Pro Max"
}'
Any specific detail of the order can be updated using this API
{
"product_name": "iPhone 15 pro max"
}
Status Code : 200
Body
{
"message": "Order updated successfully!",
"order": {
"id": 1,
"user_id": "1",
"product_id": "98765",
"product_name": "iPhone 15 Pro Max",
"product_amount": 120.00,
"qty": 3,
"tax_amt": 12.00,
"total_amt": 372.00
}
}
- Any valid field of the Order can be updated using this API
- If
Order Id
does not exists, then status code 404 should be displayed with following message in the response
{
"message": "Order not found!"
}
- Currently, no check is added for duplicate orders.
- If Authentication token is not provided, then status code 403 should be displayed with the following message in response:
{
"message": "Forbidden! Token is missing!",
}
- If token validation fails, then status code - 404 should be displayed with the following message in response:
{
"message": "No Order found with the given Order Id!!",
}
This API will delete the order of the given Order Id. It requires Authentication token in the request header that could be taken using the /auth
API.
curl --location --request DELETE 'http://localhost:3004/deleteOrder/1' \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzI1MzU1MTM0LCJleHAiOjE3MjUzNTg3MzR9.URm8jqhNUPhXjbcDzrbWp7K9RK8boZw-4s1WTtGgnI0'
Status Code : 204
No Response Body will be generated
- Any valid Order id can be deleted.
- If
Order Id
does not exists, then status code - 404 should be displayed with following message in the response
{
"message": "Order not found!"
}
- If Authentication token is not provided, then status code - 403 should be displayed with the following message in response:
{
"message": "Forbidden! Token is missing!",
}
- If token validation fails, then status code - 404 should be displayed with the following message in response:
{
"message": "No Order found with the given Order Id!!",
}
This API will create a fresh token using the following credentials that needs to be supplied in the payload:
{
"username": "admin",
"password": "secretPass123"
}
curl --location 'http://localhost:3004/auth' \
--header 'Content-Type: application/json' \
--data '{"username": "admin", "password": "secretPass123"}'
Status Code : 201
Body
{
"message": "Authentication Successful!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNzI1MzQyOTAwLCJleHAiOjE3MjUzNDY1MDB9.H5NrylQbqu3TAnqRNCOUE1pG25viLMmyfBf7gTVet-g"
}
-
username
andpassword
are mandatory fields in the request payload. - If
username
orpassword
fields are not supplied, then status code - 400 should be displayed with the following message:
{
"message": "Username and Password is required for authentication!"
}
- If
username
andpassword
does not match, authentication will fail with status code - 401 and following message
{
"message": "Authentication Failed! Invalid username or password!"
}