CRUD Operations of a User.
User Api implementation backend has done by the Spring Boot framework. It's about how a user can register and Authenticate through a JWT token and how can a user access the data provided the respective user.
Listing the technologies and frameworks used in the project.
- Spring Boot
- Spring Security
- JWT (JSON Web Tokens)
- Database used MySQL
User Table:
- id (Primary Key)
- username (Unique)
- email (Unique)
- password (Hashed)
- full_name
- age
- gender
Store Data:
-key_id(Primary Key)
-value
Instructions on how to set up the project locally for development and testing.
List of software and tools required to run the project locally.
- Java 11 or higher
- Maven
- Database: MySQL
Step-by-step instructions on how to install and run the project:
- Clone the repository to your local machine:
git clone https://github.com/your-username/your-repository.git
cd your-repository
- Build the project using Maven:
mvn clean install
-
Set up the database schema and connection:
- Create a database in your chosen database server MySQL
- Update the database configuration in
application.properties
with the correct database URL, username, and password.
-
Run the application:
mvn spring-boot:run
or
You can open the Spring Boot Main Application and can run the applicationfrom there.
The application should now be running on http://localhost:8080
.
Listing and explaining each API endpoint with sample request and response data.
- Endpoint:
POST /api/register
- Request:
{ "username": "example_user", "email": "user@example.com", "password": "secure_password123", "full_name": "John Doe", "age": 30, "gender": "male" }
- Success Response:
{ "status": "success", "message": "User successfully registered!", "data": { "user_id": "12345", "username": "example_user", "email": "user@example.com", "full_name": "John Doe", "age": 30, "gender": "male" } }
- Error Response:
{ "status": "error", "code": "INVALID_REQUEST", "message": "Invalid request. Please provide all required fields: username, email, password, full_name." }
- Endpoint:
POST /api/token
- Request:
{ "username": "example_user", "password": "secure_password123" }
- Response:
{ "status": "success", "message": "Access token generated successfully.", "data": { "access_token": "<TOKEN>", "expires_in": 3600 } }
For Accessing the data you need to use Authentication header to store the required token and token will be starts with "Bearer token"
- Endpoint:
POST /api/data
- Request:
{ "key": "unique_key", "value": "data_value" }
- Response:
{ "status": "success", "message": "Data stored successfully." }
- Endpoint:
PUT /api/data/{key}
- Request:
{ "value": "updated_data_value" }
- Response:
{ "status": "success", "message": "Data updated successfully." }
- Endpoint:
DELETE /api/data/{key}
- Response:
{ "status": "success", "message": "Data deleted successfully." }