This README provides instructions for testing the API endpoints using Postman.
To test the API endpoints in Postman with the admin access, follow these steps:
POST /api/v1/auth/login
{
"email": "admin@admin.com",
"password": "12345"
}
- Open Postman.
- Set the request method to
POST
. - Enter the URL:
http://localhost:8080/api/v1/auth/login
. - Go to the
Body
tab, selectraw
, and chooseJSON
format. - Paste the above JSON into the request body.
- Click
Send
.
You should receive a response with a JWT token if the login is successful.
{
"success": true,
"message": "login successfully",
"user": {
"_id": "user_id_here",
"name": "Admin Name",
"email": "admin@admin.com",
"phone": "1234567890",
"address": "Admin Address",
"role": 1
},
"token": "your_jwt_token_here"
}
GET /api/v1/auth/admin-auth
Add the Authorization
header with the value Bearer <your_jwt_token_here>
.
- Copy the JWT token received from the login response.
- Open a new request in Postman.
- Set the request method to
GET
. - Enter the URL:
http://localhost:8080/api/v1/auth/admin-auth
. - Go to the
Headers
tab and add theAuthorization
header with the valueBearer <your_jwt_token_here>
. - Click
Send
.
If the token is valid and the user has admin privileges, you should receive:
{
"ok": true
}
You can follow a similar approach for other endpoints that require admin access. Just ensure you:
- Include the
Authorization
header with theBearer <your_jwt_token_here>
value. - Use the appropriate HTTP method (GET, POST, PUT, DELETE) and URL as required by the endpoint you are testing.
POST /api/v1/category/create-category
{
"name": "New Category"
}
- Open a new request in Postman.
- Set the request method to
POST
. - Enter the URL:
http://localhost:8080/api/v1/category/create-category
. - Go to the
Headers
tab and add theAuthorization
header with the valueBearer <your_jwt_token_here>
. - Go to the
Body
tab, selectraw
, and chooseJSON
format. - Paste the above JSON into the request body.
- Click
Send
.
If the request is successful, you should get a response like:
{
"success": true,
"message": "new category created",
"category": {
"_id": "category_id_here",
"name": "New Category",
"slug": "new-category"
}
}
The base URL for all API endpoints is:
http://localhost:8080/api/v1
Replace localhost:8080
with the appropriate host and port if different.
Endpoint: /api/v1/auth/register
Method: POST
Body:
{
"name": "string",
"email": "string",
"password": "string",
"phone": "string",
"address": "string",
"answer": "string"
}
Endpoint: /api/v1/auth/login
Method: POST
Body:
{
"email": "string",
"password": "string"
}
Success Response:
{
"success": true,
"message": "login successfully",
"user": {
"_id": "string",
"name": "string",
"email": "string",
"phone": "string",
"address": "string",
"role": "number"
},
"token": "string"
}
Failure Response:
{
"success": false,
"message": "Invalid email or password"
}
Endpoint: /api/v1/auth/forgot-password
Method: POST
Body:
{
"email": "string",
"answer": "string",
"newPassword": "string"
}
Success Response:
{
"success": true,
"message": "Password Reset Successfully"
}
Endpoint: /api/v1/auth/register
Method: POST
Body: See Authentication Register
Endpoint: /api/v1/auth/login
Method: POST
Body: See Authentication Login
Endpoint: /api/v1/auth/forgot-password
Method: POST
Body: See Authentication Forgot Password
Endpoint: /api/v1/auth/test
Method: GET
Headers: Authorization: Bearer <token>
Success Response:
"Protected Routes"
Endpoint: /api/v1/auth/profile
Method: PUT
Headers: Authorization: Bearer <token>
Body:
{
"name": "string",
"email": "string",
"password": "string",
"address": "string",
"phone": "string"
}
Endpoint: /api/v1/category/create-category
Method: POST
Headers: Authorization: Bearer <token>
Body:
{
"name": "string"
}
Endpoint: /api/v1/category/update-category/:id
Method: PUT
Headers: Authorization: Bearer <token>
Body:
{
"name": "string"
}
Endpoint: /api/v1/category/get-category
Method: GET
Endpoint: /api/v1/category/single-category/:slug
Method: GET
Endpoint: /api/v1/category/delete-category/:id
Method: DELETE
Headers: Authorization: Bearer <token>
Endpoint: /api/v1/product/create-product
Method: POST
Headers: Authorization: Bearer <token>
Body: Form-data including:
name
(string)description
(string)price
(number)category
(string or ObjectId)quantity
(number)shipping
(boolean)photo
(file)
Endpoint: /api/v1/product/update-product/:pid
Method: PUT
Headers: Authorization: Bearer <token>
Body: Form-data including:
name
(string)description
(string)price
(number)category
(string or ObjectId)quantity
(number)shipping
(boolean)photo
(file)
Endpoint: /api/v1/product/get-product
Method: GET
Endpoint: /api/v1/product/get-product/:slug
Method: GET
Endpoint: /api/v1/product/product-photo/:pid
Method: GET
Endpoint: /api/v1/product/delete-product/:pid
Method: DELETE
Headers: Authorization: Bearer <token>
Endpoint: /api/v1/product/product-count
Method: GET
Endpoint: /api/v1/product/product-list/:page
Method: GET
Endpoint: /api/v1/product/search/:keyword
Method: GET
Endpoint: /api/v1/product/related-product/:pid/:cid
Method: GET
Endpoint: /api/v1/product/product-category/:slug
Method: GET
- Ensure that your server is running before testing.
- Use valid tokens for protected routes.
- Validate your input data according to the schema.
-Created By Amar Gupta