This project provides a REST API example using Quarkus with a reactive MongoDB client. The project stores user data in MongoDB and provides access to this data through various API endpoints.
Technology | Version |
---|---|
Quarkus | 3.12.3 |
Java | 21 |
MongoDB | 4.4 |
Hibernate Reactive | 1.0 |
RestEasy Reactive | 2.0 |
MapStruct | 1.4.2.Final |
HTTP Method | Endpoint | Description |
---|---|---|
GET | /users |
Retrieves all users with pagination. |
GET | /users/find/{id} |
Retrieves a user by ID. |
GET | /users/name/{userName} |
Retrieves users by name with pagination. |
GET | /users/age/{age} |
Retrieves users by age with pagination. |
GET | /users/email-domain/{domain} |
Retrieves users by email domain with pagination. |
POST | /users/create |
Creates a new user. |
PUT | /users/update/{id} |
Updates an existing user. |
DELETE | /users/delete/{id} |
Deletes a user by ID. |
Follow these steps to set up and run the project:
-
Install project dependencies:
mvn clean install
-
Start the application:
./mvnw quarkus:dev
-
Verify the application is running:
Open your browser and go to
http://localhost:8080
.
Add the following MongoDB connection settings to the application.properties
file:
quarkus.mongodb.connection-string = mongodb://localhost:27017
quarkus.mongodb.database = yourDatabaseName
The project uses centralized error handling to catch errors such as 404 and 500, and returns a structured error response. Error responses are returned in the following format:
{
"errorId": "unique-error-id",
"errors": ["Error message"],
"message": "General error message",
"statusCode": 404,
"timestamp": "2024-07-18T13:03:01.637531335"
}
The API endpoints support pagination. The page and size query parameters determine the page and the number of items per page. For example, /users?page=1&size=10
returns the second page with 10 users.
The user model includes the following fields:
id
: The unique identifier of the username
: The name of the userage
: The age of the useremail
: The email address of the useraddress
: The address of the usercreatedDate
: The creation date of the user
The UserDTO (Data Transfer Object) includes the following fields:
id
: The unique identifier of the username
: The name of the userage
: The age of the useremail
: The email address of the useraddress
: The address of the user
MapStruct is used to transform between the user model and the DTO.
If you would like to contribute to the project, please fork the repository and submit a pull request with your changes. If you have any questions or suggestions, feel free to contact us.