Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
firstline1
titleSync Call
linenumberstrue
collapsetrue
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
languagejava
titledeclaration
linenumberstrue
collapsetrue
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);
}

...