...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
String response = webClient .get() .uri(resourceUrl) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .retrieve() .onStatus(HttpStatus::is4xxClientError, error -> Mono.error(new RuntimeException("API not found"))) .onStatus(HttpStatus::is5xxServerError, error -> Mono.error(new RuntimeException("Server is not responding"))) .bodyToMono(String.class) .block(); return ResponseEntity.ok(response); |
...
Async call example with
...
subscription
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public Mono<String> httpOperationWithJsonData(final HttpMethod httpMethod, final String resourceUrl, final String jsonData, final HttpHeaders httpHeaders) { return webClient .get() .uri(resourceUrl) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .retrieve() .onStatus(HttpStatus::is4xxClientError, error -> Mono.error(new RuntimeException("API not found"))) .onStatus(HttpStatus::is5xxServerError, error -> Mono.error(new RuntimeException("Server is not responding"))) .bodyToMono(String.class); } |
...