Welcome to the Spring Boot Backend API, a personal project developed to demonstrate a robust backend system with authentication, role-based access control, and seamless database integration. This API is designed for learning and showcasing best practices in Spring Boot, JWT Authentication, and MySQL.
This project serves as a learning platform and a showcase of my skills in developing secure and scalable backend systems. It features:
- Authentication and Authorization: Secured using JWT.
- Role-Based Access Control: Differentiates functionality for admin and regular users.
- Product Management: Create, update, delete, and view products (restricted by roles).
- Database Integration: Powered by MySQL, running on a Docker container for easy scalability.
- CORS Configuration: Configured to allow communication with frontend applications.
🚀 Deployment: The API is deployed on Render, a free-tier cloud hosting platform.
The API may take a few seconds to load for the first request after a period of inactivity. This is due to the free-tier deployment on Render, which puts the server to sleep when not in use. Please be patient while the server starts up.
🌐 Base URL:
https://springbackend-proj.onrender.com
-
🔐 Register a User
- Endpoint:
POST /api/v1/auth/register - Request Body:
{ "firstname": "John", "lastname": "Doe", "email": "john.doe@example.com", "password": "securePassword", "isAdmin": "false" // Set "true" for admin users } - Response:
{ "token": "JWT_TOKEN" }
- Endpoint:
-
🔑 Login
- Endpoint:
POST /api/v1/auth/authenticate - Request Body:
{ "email": "john.doe@example.com", "password": "securePassword" } - Response:
{ "token": "JWT_TOKEN", "isAdmin": true // or false based on the user's role }
- Endpoint:
-
🔄 Change Password
- Endpoint:
POST /api/v1/users/change-password - Headers:
Authorization: Bearer JWT_TOKEN - Request Body:
{ "currentPassword": "oldPassword", "newPassword": "newSecurePassword", "confirmPassword": "newSecurePassword" } - Response:
200 OKif successful.
- Endpoint:
-
👑 Admin-Only Actions
- Endpoint: Any
/api/v1/users/**(e.g.,GET /api/v1/users/all) - Requires Admin token.
- Endpoint: Any
-
🆕 Create a Product (Admin Only)
- Endpoint:
POST /api/v1/products - Headers:
Authorization: Bearer JWT_TOKEN - Request Body:
{ "productName": "Sample Product", "productPrice": 99.99 } - Response:
201 Createdwith product details.
- Endpoint:
-
📖 Get All Products
- Endpoint:
GET /api/v1/products - Response:
[ { "productId": 1, "productName": "Sample Product", "productPrice": 99.99 } ]
- Endpoint:
-
✏️ Update a Product (Admin Only)
- Endpoint:
PUT /api/v1/products/{id} - Headers:
Authorization: Bearer JWT_TOKEN - Request Body:
{ "productName": "Updated Product Name", "productPrice": 79.99 } - Response:
- Updated product details.
- Endpoint:
-
🗑️ Delete a Product (Admin Only)
- Endpoint:
DELETE /api/v1/products/{id} - Headers:
Authorization: Bearer JWT_TOKEN - Response:
204 No Contentif successful.
- Endpoint:
- ✨ Import Endpoints: Copy the API endpoints into Postman or create requests manually as described above.
- 🔐 Authentication:
- Use the
POST /api/v1/auth/authenticateendpoint to obtain yourJWT_TOKEN. - For protected endpoints, add the token to the
Authorizationheader:Authorization: Bearer YOUR_JWT_TOKEN
- Use the
- 🌐 Base URL: Prefix all endpoints with:
https://springbackend-proj.onrender.com - 📤 Test Requests: Use the sample request bodies and headers provided above.
- Only admin users can perform create, update, and delete actions for products.
- Ensure proper authentication by including the token in the
Authorizationheader for protected endpoints. - First-time requests may take a few seconds due to server startup on free-tier hosting.
Thank you for exploring the Spring Boot Backend API! 🚀