This is a simple REST API project for managing users, built using Java 17, Spring Boot, and MongoDB. It supports creating, updating, listing, and toggling user activation status.
POST /api/create-user– Create a new userPOST /api/update-user– Update existing user detailsGET /api/users– List all usersPOST /api/toggle-user?id=– Activate or deactivate a user.ideafolder removed and include in.gitignore- Includes basic unit testing cases
- Proper Git Branching and Pull Request for workflow followed
{
"_id": "ObjectId",
"email": "string",
"firstName": "string",
"lastName": "string",
"isActive": true,
"tenantId": "string",
"createdAt": "datetime",
"updatedAt": "datetime"
}-
Java 17
-
Spring Boot 3.2.4
-
MongoDB (local)
-
Maven
-
IntelliJ IDEA
-
Git & GitHub
-
Postman (for API testing)
-
Swagger (springdoc-openapi-ui)
user-api-springboot/
├── src/
│ ├── main/
│ │ ├── java/com/example/userapi/
│ │ │ ├── controller/ # REST API controllers
│ │ │ ├── model/ # User model
│ │ │ ├── repository/ # MongoDB repository
│ │ │ └── service/ # Business logic
│ │ └── resources/
│ │ ├── application.properties
│ │ └── static/
│ │ └── swagger-ui.png # Swagger screenshot (if added)
│
│ ├── test/
│ │ └── java/com/example/userapi/
│ │ ├── DummyTest.java # Basic test to verify setup
│
├── .gitignore # Now includes `.idea/`
├── pom.xml # Maven project file with dependencies
├── README.md # Full documentation
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/create-user |
Create a new user |
| POST | /api/update-user |
Update existing user info |
| GET | /api/users |
Fetch list of all users |
| POST | /api/toggle-user |
Toggle user activation by ID |
-
MongoDB running locally on
mongodb://localhost:27017 -
Java 17 installed
-
IntelliJ IDEA (or other Java IDE)
1. Clone the repo:
git clone https://github.com/srijeeta0425/user-api-springboot.git
2. Open the project in IntelliJ IDEA
3. Configure MongoDB if needed in:
src/main/resources/application.properties
4. Run the application:
Open UserApiApplication.java
Click the green Run button or use Shift + F10
5. Test the API in Swagger UI:
# Install dependencies and build the project
mvn clean install
# Run the Spring Boot application
mvn spring-boot:run
The application runs on:
http://localhost:8080
-
Download MongoDB Community Edition from MongoDB Downloads
-
Start MongoDB server (default port is 27017)
-
Make sure MongoDB is running
-
In application.properties, set the URI:
spring.data.mongodb.uri=mongodb://localhost:27017/user-api-db
Spring Boot will auto-create the collections.
Included dependency in pom.xml:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.14</version>
</dependency>
Swagger Endpoints:
-
Swagger UI: http://localhost:8080/swagger-ui.html
-
OpenAPI JSON: http://localhost:8080/v3/api-docs
A .gitignore file was added to exclude unnecessary files:
# Build output
/target/
# IDE settings
/.idea/
*.iml
# OS clutter
.DS_Store
Thumbs.db

POSTrequest to/api/create-user:
{
"email": "[email protected]",
"firstName": "Srijeeta",
"lastName": "Purkait",
"tenantId": "getpostlabs123"
}
POSTrequest to/api/update-user:
{
"email": "[email protected]",
"firstName": "Updated",
"lastName": "Name",
"tenantId": "newTenant"
}
3.GET request to /api/users:
{
"email": "[email protected]",
"firstName": "Srijeeta",
"lastName": "Purkait",
"tenantId": "getpostlabs123"
}
POSTrequest to/api/toggle-user:
{
"email": "[email protected]",
"firstName": "Updated",
"lastName": "Name",
"tenantId": "newTenant"
}
Srijeeta Purkait
Software Engineer Trainee– [GetPost Labs]
📫 Email: [email protected]
🔗 GitHub: https://github.com/srijeeta0425/user-api-springboot/tree/master