{"id":18752301,"url":"https://github.com/hendisantika/spring-boot-rest-client","last_synced_at":"2026-04-10T21:03:15.160Z","repository":{"id":254121505,"uuid":"845543208","full_name":"hendisantika/spring-boot-rest-client","owner":"hendisantika","description":"Spring Boot Rest Client Sample","archived":false,"fork":false,"pushed_at":"2025-02-18T00:16:34.000Z","size":94,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-18T01:23:44.211Z","etag":null,"topics":["rest-client","spring","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hendisantika.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-21T13:01:36.000Z","updated_at":"2025-02-18T00:16:31.000Z","dependencies_parsed_at":"2024-08-21T15:04:36.612Z","dependency_job_id":"a2f6d9c1-68b6-4a69-928f-4908c951e8a4","html_url":"https://github.com/hendisantika/spring-boot-rest-client","commit_stats":null,"previous_names":["hendisantika/spring-boot-rest-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hendisantika%2Fspring-boot-rest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hendisantika%2Fspring-boot-rest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hendisantika%2Fspring-boot-rest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hendisantika%2Fspring-boot-rest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hendisantika","download_url":"https://codeload.github.com/hendisantika/spring-boot-rest-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239643627,"owners_count":19673574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rest-client","spring","spring-boot"],"created_at":"2024-11-07T17:19:45.104Z","updated_at":"2026-04-10T21:03:15.153Z","avatar_url":"https://github.com/hendisantika.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Boot REST Client\n\nA comprehensive Spring Boot application demonstrating the use of Spring's modern RestClient for consuming REST APIs,\nwith full CRUD operations, database integration, and API documentation.\n\n## Technologies Used\n\n- **Java 21** - Modern Java features and performance improvements\n- **Spring Boot 3.5.7** - Latest Spring Boot framework\n- **Spring Data JPA** - Data persistence layer\n- **Hibernate 6.6** - ORM framework\n- **MySQL 9.1** - Database (via Docker Compose)\n- **Spring RestClient** - Modern HTTP client for consuming REST APIs\n- **Lombok** - Reduces boilerplate code\n- **SpringDoc OpenAPI 2.8.14** - API documentation (Swagger UI)\n- **JUnit 5** - Unit and integration testing\n- **Testcontainers** - Database testing with containers\n- **Docker Compose** - Container orchestration for MySQL\n\n## Features\n\n- Modern RestClient implementation for consuming external APIs\n- Full CRUD operations for Employee and User entities\n- RESTful API endpoints with proper HTTP methods\n- Automatic database schema management with Hibernate\n- Comprehensive unit tests with @RestClientTest\n- Integration tests (disabled by default, requires running application)\n- API documentation with Swagger UI\n- Docker Compose integration for MySQL database\n- Development tools with hot reload\n\n## Prerequisites\n\n- Java 21 or higher\n- Maven 3.6+\n- Docker and Docker Compose (for database)\n\n## Project Structure\n\n```\nsrc/main/java/id/my/hendisantika/springbootrestclient/\n├── client/\n│   ├── PostClient.java          # Client for consuming JSONPlaceholder API\n│   └── RestClientService.java   # Service demonstrating RestClient usage\n├── controller/\n│   ├── EmployeeController.java  # Employee REST endpoints\n│   └── UserController.java      # User REST endpoints\n├── converter/\n│   └── EmployeeConverter.java   # DTO/Entity converter\n├── dto/\n│   ├── EmployeeDto.java         # Employee data transfer object\n│   └── Post.java                # Post DTO for external API\n├── entity/\n│   ├── Employee.java            # Employee JPA entity\n│   └── User.java                # User JPA entity\n├── repository/\n│   ├── EmployeeJdbcRepository.java\n│   ├── EmployeeRepository.java\n│   └── UserRepository.java\n├── service/\n│   ├── EmployeeService.java\n│   └── UserService.java\n└── SpringBootRestClientApplication.java\n```\n\n## Getting Started\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/hendisantika/spring-boot-rest-client.git\ncd spring-boot-rest-client\n```\n\n### 2. Build the project\n\n```bash\nmvn clean install\n```\n\n### 3. Run the tests\n\n```bash\nmvn test\n```\n\nAll unit tests should pass:\n\n- PostClientTest - Tests for consuming external APIs\n- EmployeeClientTest - Tests for RestClientService\n- SpringBootRestClientApplicationTests - Context loading test\n\nNote: Integration tests in `RestClientTest.java` are disabled by default as they require the application to be running.\n\n### 4. Run the application\n\n```bash\nmvn spring-boot:run\n```\n\nThe application will:\n\n1. Start Docker Compose and create a MySQL container\n2. Initialize the database schema automatically\n3. Start the embedded Tomcat server on port 8080\n4. Enable Swagger UI for API documentation\n\n## API Endpoints\n\n### Employee Endpoints\n\n- `GET /api/employees` - Get all employees\n- `GET /api/employees/{id}` - Get employee by ID\n- `POST /api/employees` - Create new employee\n- `PUT /api/employees/{id}` - Update employee\n- `DELETE /api/employees/{id}` - Delete employee\n\n### User Endpoints\n\n- `GET /api/users` - Get all users\n- `GET /api/users/{id}` - Get user by ID\n- `POST /api/users` - Create new user\n- `PUT /api/users/{id}` - Update user\n- `DELETE /api/users/{id}` - Delete user\n\n## API Documentation\n\nOnce the application is running, access the Swagger UI at:\n\n```\nhttp://localhost:8080/swagger-ui.html\n```\n\nOpenAPI JSON specification is available at:\n\n```\nhttp://localhost:8080/v3/api-docs\n```\n\n## Example Usage\n\n### Create Employee\n\n```bash\ncurl -X POST http://localhost:8080/api/employees \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"firstName\": \"John\",\n    \"lastName\": \"Doe\",\n    \"email\": \"john.doe@example.com\"\n  }'\n```\n\n### Get All Employees\n\n```bash\ncurl http://localhost:8080/api/employees\n```\n\n### Update Employee\n\n```bash\ncurl -X PUT http://localhost:8080/api/employees/1 \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"firstName\": \"Jane\",\n    \"lastName\": \"Doe\",\n    \"email\": \"jane.doe@example.com\"\n  }'\n```\n\n### Delete Employee\n\n```bash\ncurl -X DELETE http://localhost:8080/api/employees/1\n```\n\n## RestClient Implementation\n\nThis project demonstrates Spring's modern `RestClient` API for consuming external REST services. The `PostClient` class\nshows how to:\n\n- Configure RestClient with base URLs\n- Make GET requests to external APIs\n- Parse JSON responses into Java objects\n- Handle errors and exceptions\n\nExample from `PostClient.java`:\n\n```java\n\n@Service\npublic class PostClient {\n    private final RestClient restClient;\n\n    public PostClient(RestClient restClient) {\n        this.restClient = restClient;\n    }\n\n    public List\u003cPost\u003e findAll() {\n        return restClient.get()\n                .uri(\"/posts\")\n                .retrieve()\n                .body(new ParameterizedTypeReference\u003c\u003e() {\n                });\n    }\n}\n```\n\n## Database Configuration\n\nThe application uses Docker Compose to automatically start a MySQL container. Configuration is in `compose.yml`:\n\n- **Database**: MySQL 9.1\n- **Port**: 3306\n- **Database Name**: employeedb\n- **Username**: root\n- **Password**: Password123\n\nDatabase schema is automatically created by Hibernate on startup.\n\n## Testing\n\n### Unit Tests\n\nRun unit tests with:\n\n```bash\nmvn test\n```\n\nUnit tests use `@RestClientTest` to test REST client implementations without starting the full application context.\n\n### Integration Tests\n\nIntegration tests in `RestClientTest.java` are disabled by default. To run them:\n\n1. Start the application: `mvn spring-boot:run`\n2. Remove the `@Disabled` annotation from `RestClientTest.java`\n3. Run the tests: `mvn test`\n\n## Configuration\n\nApplication properties can be configured in `src/main/resources/application.yml`:\n\n- Server port\n- Database connection\n- Hibernate settings\n- Logging levels\n- API documentation settings\n\n## Development\n\nThe project includes Spring DevTools for hot reload during development. Any changes to Java files will automatically\nrestart the application.\n\n## Production Considerations\n\nFor production deployment:\n\n1. Disable Swagger UI:\n   ```properties\n   springdoc.swagger-ui.enabled=false\n   springdoc.api-docs.enabled=false\n   ```\n\n2. Configure proper database credentials\n3. Enable security (not included in this demo)\n4. Configure proper logging levels\n5. Use production-grade database instead of Docker Compose\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.\n\n## Author\n\n**Hendi Santika**\n\n- Email: hendisantika@gmail.com\n- Telegram: @hendisantika34\n\n## Acknowledgments\n\n- [Spring Boot Documentation](https://spring.io/projects/spring-boot)\n- [Spring RestClient Guide](https://docs.spring.io/spring-framework/reference/integration/rest-clients.html)\n- [SpringDoc OpenAPI](https://springdoc.org/)\n- [JSONPlaceholder](https://jsonplaceholder.typicode.com/) - Free fake API for testing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhendisantika%2Fspring-boot-rest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhendisantika%2Fspring-boot-rest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhendisantika%2Fspring-boot-rest-client/lists"}