Learn to use RestTemplateBuilder to create or build RestTemplate class which can be used to send HTTP requests. 1) Default RestTemplateBuilder To inject RestTemplateBuilder, pass it as constructor argument in your service class. 2) Custom RestTemplateBuilder To create custom RestTemplateBuilder, create @Bean of type RestTemplateBuilder in Spring context. RestTemplateBuilder Bean RestTemplateCustomizer Bean Create custom RestTemplateCustomizer […]
Learn to use ClientHttpRequestInterceptor with Spring RestTemplate to log request and response headers and body in Spring AOP style. Interceptor Usages We can use this interceptor for many useful tasks. To add custom header to the response To log HTTP request and response To deny certain requests etc. 1) Interceptor to log request and response […]
We have already gone through the RestTemplate examples for accessing REST APIs inside spring application. In this example, we are extending the configuration to use Apache HttpClient 4. The purpose of this tutorial is to give you pre-cooked recipe for little head-start, and save you from writing all bits and pieces.
After learning to build Spring REST based RESTFul APIs for XML representation and JSON representation, let’s build a RESTFul client to consume APIs which we have written. Accessing a third-party REST service inside a Spring application revolves around the use of the Spring RestTemplate class. The RestTemplate class is designed on the same principles as […]
In Spring REST XML tutorial, we learned about building RESTFul APIs which were able to return XML representations of resources. In this tutorial, we will learn to write APIs capable of returning JSON representations of resources. 1) Using @ResponseBody Annotation This technique is simple and easy. You have to include only jackson dependencies into classpath […]
In this tutorial, I am writing hello world example for RESTful APIs using Spring REST features. In this example, I will be creating two APIs which will return XML representation of resources. Maven Dependencies Let’s start with runtime dependencies which you will need to write these RESTFul APIs. In fact, all you need is Spring […]