https://github.com/mgunawardhana/call-rest-api-using-web-client
This Java package demonstrates how to call a REST API using the Spring WebFlux WebClient.
https://github.com/mgunawardhana/call-rest-api-using-web-client
external-api java rest-api spring-boot webflux
Last synced: about 2 months ago
JSON representation
This Java package demonstrates how to call a REST API using the Spring WebFlux WebClient.
- Host: GitHub
- URL: https://github.com/mgunawardhana/call-rest-api-using-web-client
- Owner: mgunawardhana
- Created: 2024-04-09T12:56:29.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-19T15:17:56.000Z (about 2 years ago)
- Last Synced: 2026-03-05T13:26:28.556Z (3 months ago)
- Topics: external-api, java, rest-api, spring-boot, webflux
- Language: Java
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Call REST API Using WebClient
This Java package demonstrates how to call a REST API using the Spring WebFlux `WebClient`.
## Introduction
This project provides a simple example of how to make HTTP requests to a REST API using the `WebClient` class provided by the Spring Framework. It fetches data from the [Fake Store API](https://fakestoreapi.com/) and demonstrates how to handle both a list of products and a single product response.
## Dependencies
This project requires:
- Java Development Kit (JDK) version 8 or higher
- Spring Boot
- Lombok
## Usage
1. Clone this repository to your local machine.
2. Build the project using your preferred IDE or build tool.
3. Run the `CallRestApiUsingWebClientApplication` class.
4. The application will fetch a list of products from the Fake Store API and log the response.
5. It will also fetch a single product with ID 1 and log the response.
## Code Explanation
- The `main` method in the `CallRestApiUsingWebClientApplication` class initializes a Spring Boot application.
- It uses `WebClient.Builder` to create a `WebClient` instance.
- The first request fetches a list of products from the specified URI and logs the response.
- The second request fetches a single product with ID 1 and logs the response.
## Further Information
For more details about Spring WebFlux and `WebClient`, please refer to the [official documentation](https://docs.spring.io/spring-framework/reference/web/webflux.html).
## License
This project is licensed under the [MIT License](LICENSE).