This guide helps you test the API endpoints of the Ecommerce application using Postman.
- Endpoint:
POST /auth/register - URL:
http://localhost:8080/auth/register - Body (JSON):
{
"username": "testuser",
"password": "testpassword",
"email": "testuser@example.com"
}- Description: Registers a new user and returns an authentication token.
- Endpoint:
POST /auth/login - URL:
http://localhost:8080/auth/login - Body (JSON):
{
"username": "testuser",
"password": "testpassword"
}-
Description: Logs in the user and returns a JWT token.
-
Save the JWT token from the response for use in subsequent requests.
- In Postman, go to the Headers tab for your requests.
- Add a header:
- Key:
Authorization - Value:
Bearer YOUR_JWT_TOKEN_HERE
- Key:
- Replace
YOUR_JWT_TOKEN_HEREwith the token received from the login response.
- Endpoint:
POST /api/products - URL:
http://localhost:8080/api/products - Body: Use
form-datain Postman- Key:
product(type: text)- Value (JSON string):
{ "name": "Sample Product", "description": "This is a sample product", "price": 19.99, "category": "Sample Category" } - Key:
image(type: file) - optional, upload an image file
- Key:
- Endpoint:
GET /api/products/search - URL:
http://localhost:8080/api/products/search?query=sample - Description: Searches products by query string.
- Endpoint:
GET /api/products/paged - URL:
http://localhost:8080/api/products/paged?page=0&size=10 - Description: Gets paged list of products.
- Endpoint:
GET /api/products - URL:
http://localhost:8080/api/products - Description: Gets list of all products.
- Endpoint:
GET /api/products/mine - URL:
http://localhost:8080/api/products/mine - Description: Gets products created by the logged-in seller.
- These endpoints require specific roles and authorization.
| Endpoint | URL | Role Required | Description |
|---|---|---|---|
| GET /api/test/admin | http://localhost:8080/api/test/admin | Admin | Access for admin only |
| GET /api/test/seller | http://localhost:8080/api/test/seller | Seller | Access for seller only |
| GET /api/test/buyer | http://localhost:8080/api/test/buyer | Buyer | Access for buyer only |
| GET /api/test/any | http://localhost:8080/api/test/any | Admin or Seller | Access for admin or seller |
- Use the JWT token of a user with the appropriate role to test these endpoints.
- Replace
http://localhost:8080with your actual server URL if different. - Ensure your server is running before testing.
- Use the token from login to authorize requests that require authentication.
This guide should help you test all main endpoints and functionality of your app using Postman.