- Angela DeLeo
- Roman Saddi
- Joshua Lai
- Belal Skaik
- Nicholas Haga
This is the midterm project for CPSC 449. The goal of the project is to create a simple RESTful API for a store that sells products. Authentication is based on tokens and email/password login.
-
The API allows retailers to create a new product, update an existing product, and delete a product. Retailers have moderate access to the API, only able to modify their products.
-
The API allows users to view the cart, add items to the cart, remove items from the cart, update their password, and delete their account. Users have the least access to the API, only able to modify their individual cart and account.
-
The API allows admin to delete users, update users, view all users, delete products, and update products. Admin has full access to everything in the API.
- Install npm dependencies:
npm install
- Start the server locally:
npm start
- Test the API using a tool like Postman
- Open Postman and type
https://localhost:3000
into the URL bar
For testing the products component, follow these instructions:
- Open Postman and type
https://localhost:3000
into the URL bar - To view a list of all products, send a GET request to
https://localhost:3000/products
- To view a specific product, send a GET request to
https://localhost:3000/products/:id
where:id
is the ID of the product you want to view - To create retailer account, send a POST request to
https://localhost:3000/products/register
with the retailer data in the request body (see the "Retailer Data" section below for more information) - To login to an existing retailer account, send a POST request to
https://localhost:3000/products/login
with the retailer email and password in the request body - Once a retailer is created and logged in, the following routes are available (ensure the token given during login is in the Authorization header):
- To create a new product, send a POST request to
https://localhost:3000/products
with the product data in the request body (see the "Product Data" section below for more information) - To update an existing product, send a PATCH request to
https://localhost:3000/products/:id
where:id
is the ID of the product you want to update (see the "Product Data" section below for more information) - To delete a product, send a DELETE request to
https://localhost:3000/products/:id
where:id
is the ID of the product you want to delete
- To create a new product, send a POST request to
When creating or updating a product, the request body should be a JSON object with the following fields:
name
(string, required): The name of the productprice
(number, required): The price of the productdescription
(string, optional): A description of the product
Example product data:
{
"name": "Product 1",
"price": 9.99,
"description": "A great product"
}
When creating a retailer, the request body should be a JSON object with the following fields:
name
(string, required): The name of the retaileremail
(string, required): The email of the retailerpassword
(string, required): The password of the retailerstoreName
(string, required): The name of the storerole
(string, required): The role of the retailer
Example retailer data:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123",
"storeName": "Store 1",
"role": "retailer"
}
For testing the Admin component, follow these instructions:
- Open Postman and type
https://localhost:3000
into the URL bar - To delete a user, send a DELETE request to
https://localhost:3000/admin/deleteUser
with the ID of the user (see the "User Data" for more information). - To update a user, send a PATCH request to
https://localhost:3000/admin/updateUser
with the new credentials you would like to update the user with (see the "User Data" for more information). - To delete a product, send a DELETE request to
https://localhost:3000/admin/deleteProduct
with the ID of the product (see the "Product Data" for more information). - To update a product, send a PATCH request to
https://localhost:3000/admin/updateProduct
with the new product information you would like to update the product with (see the "Product Data" for more information). - To pull all users, send a GET request to
https://localhost:3000/admin/getUsers
.
For testing the users component, follow these instructions:
- Open Postman and type
https://localhost:3000
into the URL bar - To create an account, send a POST request to
https://localhost:3000/user/register
with the new user data in the request body (see the "User Data" section below for more information) - To login to an existing account, send a POST request to
https://localhost:3000/user/login
with the user email and password in the request body - Once a user is created and logged in, the following routes are available (ensure the token given during login is in the Authorization header):
- To view the cart, send a GET request to
https://localhost:3000/user/cart
- To add an item to the cart, send a POST request to
https://localhost:3000/user/cart/
with the body containing the ID of the product to add to the cart - To remove an item from the cart, send a DELETE request to
https://localhost:3000/user/cart/
with the body containing the ID of the product to remove from the cart - To delete an account, send a DELETE request to
https://localhost:3000/user
- To update a password, send a PATCH request to
https://localhost:3000/user/pass
with the new password in the request body
- To view the cart, send a GET request to
When creating an account, the request body should be a JSON object with the following fields:
name
(string, required): The name or username of the useremail
(string, required): The email of the userpassword
(string, required): The password of the user
Example user data:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123",
"role": "customer"
}