http://localhost:4000/api
Most endpoints require JWT authentication. Add the token to your requests:
Authorization: Bearer <your_jwt_token>
GET /products
Query Parameters:
category
(optional): Filter by categorybrand
(optional): Filter by brandprice
(optional): Filter by maximum price
Example:
GET /products?category=Phone&brand=Apple&price=1000
GET /products/:slug
Example:
GET /products/iphone-14
POST /products
Authorization: Bearer <token>
Content-Type: multipart/form-data
Body:
name
(required): stringdescription
(required): stringprice
(required): numbercategory
(required): enum ['Phone', 'Computers', 'Smartwatch', 'Camera', 'Headphones', 'Gaming', 'Other']brand
(required): stringstock
(required): numberimages
(required): file(s) (up to 10 images)
PATCH /products/:id
Authorization: Bearer <token>
Content-Type: multipart/form-data
Body: Any product fields you want to update, including new images.
Example:
{
"price": 899,
"stock": 45,
"images": [file1, file2]
}
DELETE /products/:id
Authorization: Bearer <token>
POST /products/:id/reviews
Authorization: Bearer <token>
Content-Type: application/json
Body:
{
"comment": "Great product!",
"rating": 5
}
GET /products/:id/reviews
POST /user/signup
Content-Type: application/json
Body:
{
"email": "[email protected]",
"password": "StrongPass123!",
"name": "John Doe",
"role": "user"
}
POST /user/login
Content-Type: application/json
Body:
{
"email": "[email protected]",
"password": "StrongPass123!"
}
GET /user
Authorization: Bearer <token>
GET /user/search?query=<search_term>
Authorization: Bearer <token>
Example:
GET /user/search?query=admin
DELETE /user/:id
Authorization: Bearer <token>
POST /user/forgot-password
Content-Type: application/json
Body:
{
"email": "[email protected]"
}
POST /user/reset-password
Content-Type: application/json
Body:
{
"token": "reset_token_received_via_email",
"newPassword": "NewStrongPass123!"
}
PATCH /user/profile
Authorization: Bearer <token>
Content-Type: multipart/form-data
Body:
name
(optional): stringimage
(optional): file (profile image)
Example:
PATCH /user/profile
Authorization: Bearer <token>
Content-Type: multipart/form-data
Form-data:
name
: "Jane Doe"image
: (upload a file)
-
Create a Postman Collection
- Open Postman
- Create a new collection called "E-commerce API"
- Create folders for "Products" and "Users"
-
Set up Environment Variables
- Create a new environment
- Add variables:
BASE_URL
: http://localhost:4000/apiTOKEN
: (leave empty initially)
-
Authentication Flow
- Create a user using the signup endpoint
- Login with the created user
- Copy the token from the response
- Set the token in your environment variable
-
Testing Protected Routes
- Make sure to include the Authorization header:
Authorization: Bearer {{TOKEN}}
-
Testing File Uploads
- Use form-data in Postman
- Set the key type to "File" for image uploads
Example Postman Test Sequence:
- Create user (POST /user/signup)
- Login (POST /user/login)
- Update profile (PATCH /user/profile)
- Create product (POST /products)
- Get all products (GET /products)
- Add review (POST /products/:id/reviews)
- Get product reviews (GET /products/:id/reviews)
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})