Last active
March 9, 2024 08:30
-
-
Save up1/6dd5b52608aec8d4eb2798a7e44a0ec0 to your computer and use it in GitHub Desktop.
RestClient :: Spring Boot 3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get data | |
var response = restClient | |
.get() | |
.uri("/users/1") | |
.retrieve() | |
.toEntity(UserResponse.class); | |
// Error handling | |
var request = restClient | |
.get() | |
.uri("/users/1") | |
.retrieve() | |
.onStatus(HttpStatusCode::is4xxClientError, (request, response) -> { | |
throw new UserNotFoundException(response.getStatusCode(), response.getHeaders()) | |
}) | |
.body(UserResponse.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create RestClient | |
var response = RestClient.create(); | |
// Create RestClient with RestTemplate | |
var restTemplate = new RestTemplate(); | |
var response = RestClient.builder(restTemplate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment