- Clone the GitHub repo
- Open command line, navigate to the project directory, and run 'npm install'.
- Create an account on MongoDB and get a connection URI.
- Create '.env' file in the directory and the following to the file
- MONGODB_URI='YOUR_CONNECTION_URI'
- CRYPTO_SECRET='ANY_SECRET_OF_YOUR_CHOICE'
- Run 'npm start' in the command line to start the server.
For making API requests use Postman or any other application of your choice.
Endpoint: PUT '/auth/signup'
Request body: {"email": "YOUR_EMAIL", "password": "YOUR_PASSWORD", "name": "YOUR_NAME"}
Constraints:
- All fields are required
- Password should contain at least 8 characters
Endpoint: POST '/auth/login'
Request body: {"email": "YOUR_EMAIL", "password": "YOUR_PASSWORD"}
Constraints:
- All fields are required
The response will a JWT token which will be required for making API further requests.
Note that all of the following API requests will contain the following header
Authorization: Bearer {JWT_TOKEN}
The JWT token has an expiration time of 1 hour. After it has expired, a new JWT token has to be generated to make the following API requests.
Endpoint: GET '/categories'
Query parameters: 'page={PAGE_NUMBER}'
The response will contain maximum 5 categories per page. Use the query parameters to move to other pages.
For example, to view categories on page 2 the endpoint will be '/ecommerce/categories?page=2'.
Endpoint: POST '/create-product'
Request body: {"title": "TITLE_OF_PRODUCT, "price": "PRICE_OF_PRODUCT", "description": "DESCRIPTION_OF_PRODUCT", "availability": "QUANTITIY_TO_BE_ADDED", "categoryName": "CATEGORY_NAME"}
The response will be a confirmation message and the details of the newly created product.
Endpoint: GET '/product-list/{categoryId}'
The response will be a list of products belonging to the category of which category ID is passed in the url.
Endpoint: GET '/product/{productId}'
The response will be detailed version of the product.
Endpoint: PUT '/cart/add-to-cart'
Request body: {"productId": "PRODUCT_ID"}
The product with the given product ID will be added to the cart with quantity 1.
Endpoint: GET '/cart'
The response will be the list of products and their respective quantity in the cart.
Endpoint: PUT '/cart/update-product'
Request body: {"productId": "PRODUCT_ID", "quantity": "NEW_QUANTITY"}
The response will be the updated product details with new quantity.
Endpoint: PUT '/cart/remove-product'
Request body: {"productId": "PRODUCT_ID"}
The response will be a confirmation message and product ID of the product which is removed from the cart.
Endpoint: POST '/place-order'
The response will be a confirmation message and the newly placed order.
Endpoint: GET '/order-history'
The response will be a list of all orders placed in the past.
Endpoint: GET '/order/{orderId}'
The response will be a detailed version of order.