Package sk.antons.sbutils.rest
Class RestTemplateClient
java.lang.Object
sk.antons.sbutils.rest.RestTemplateClient
Helper implementation for RestTemplate usage.
<pre>
private RestTemplateClient client() {
RestTemplate template = templateBuilder
.additionalInterceptors(LoggingInterceptor
.instance()
.logger(m -> log.info(m))
.loggerEnabled(() -> log.isInfoEnabled())
.responseBody(LoggingInterceptor.Body.json().indent(" ").transform())
)
.build();
return RestTemplateClient.Builder.instance()
.template(template)
.root("https://dummy.restapiexample.com/api/v1")
.client();
}
public EmployeeResult getEmployees() {
return client().get().path("/employees").call(EmployeeResult.class);
}
</pre>- Author:
- antons
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRestTemplateClient builderstatic classDefault headers providerstatic classException thrown if an error ocures od ResponseValidator returns false.static classPath builderclassRestTemplateClient builderstatic classResponseValidator builder (check if response is ok - if not exception is thrown.) -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intprotected BiFunction<String,Object, org.springframework.http.HttpHeaders> protected Predicate<org.springframework.http.ResponseEntity>protected Stringprotected org.springframework.web.client.RestTemplate -
Method Summary
-
Field Details
-
root
-
template
protected org.springframework.web.client.RestTemplate template -
headers
-
responseValidator
-
counter
public static int counter
-
-
Method Details
-
headers
-
responseValidator
-
get
-
post
-
delete
-
head
-
put
-