This repository contains an approach to store the customers' shopping cart in Redis. This approach was based in RedisLabs usage example (see here) and another example (Cart Management Service).
This app is not docker based, so you should install Node.js, in order to run the API server.
Node.js >= 10.x
Redis
-
Run
yarn install
to install required dependencies for this project; -
Create .env file using the provided template (.env.example);
-
Run API using:
yarn start
or
node src/server.js
- Run tests using the following command:
yarn test
- Linting can be checked using:
yarn lint
The REST API endpoints is described below.
Returns json data with cart items for user specified with session_id parameter.
-
URL
/carts/:session
-
Method:
GET
-
URL Params
Required:
session=[string]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ success: true, items: { <Item ID>: <Quantity>, ...} }
- Code: 200
-
Sample Call:
curl http://localhost:3000/carts/3713ae4a-b7de-42f6-934d-9a74ac233cd5
Add new item to the cart.
-
URL
/carts/:session/items
-
Method:
POST
-
URL Params
Required:
session=[string]
-
Data Params
{ "itemId": "integer", "quantity": "integer", }
-
Success Response:
- Code: 200
Content:{ success: true }
- Code: 200
-
Error Response:
None
-
Sample Call:
curl -H "Content-Type: application/json" -X POST -d '{"itemId":900,"quantity":1}' http://localhost:3000/carts/3713ae4a-b7de-42f6-934d-9a74ac233cd5/items
Update the quantity of an existent item on customer cart.
-
URL
/carts/:session/items/:itemId
-
Method:
PUT
-
URL Params
Required:
session=[string]
itemId=[integer]
-
Data Params
{ "quantity": "integer", }
-
Success Response:
- Code: 200
Content:{ success: true }
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "status": 404, "error": "Not Found", "message": "Item not found", "path": "/3713ae4a-b7de-42f6-934d-9a74ac233cd5/items/929", "timestamp": 1578089747041 }
- Code: 404 NOT FOUND
-
Sample Call:
curl -H "Content-Type: application/json" -X PUT -d '{"quantity":3}' http://localhost:3000/carts/3713ae4a-b7de-42f6-934d-9a74ac233cd5/items/929
Delete one item from customer cart.
-
URL
/carts/:session/items/:itemId
-
Method:
DELETE
-
URL Params
Required:
session=[string]
itemId=[integer]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ success: true }
- Code: 200
-
Sample Call:
curl -X DELETE http://localhost:3000/carts/3713ae4a-b7de-42f6-934d-9a74ac233cd5/items/5455
Delete all items from customer cart.
-
URL
/carts/:session
-
Method:
DELETE
-
URL Params
Required:
session=[string]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ success: true }
- Code: 200
-
Sample Call:
curl -X DELETE http://localhost:3000/carts/3713ae4a-b7de-42f6-934d-9a74ac233cd5
- The style of describe endpoints in this file was based on following gist (https://gist.github.com/iros/3426278);