Spring RestTemplate

Basic Auth with Spring RestTemplate

Learn to add basic authentication to http requests invoked by Spring RestTemplate while accessing rest apis over the network. 1. Maven dependencies To work with Spring RestTemplate and HttpClient API, we must include spring-boot-starter-web and httpclient dependencies in pom.xml file. In this RestTemplate basic authentication tutorial, we are using dependencies. …

Configure Timeouts with Spring RestTemplate

In this Spring boot2 RestTemplate timeout example, learn to configure connection timeout and read timeout in Spring RestTemplate with example. 1. Default Timeout By default, RestTemplate uses SimpleClientHttpRequestFactory which depends on the default configuration of HttpURLConnection. Look inside the class source, and you will find this. By default, RestTemplate uses …

Spring Boot RestTemplate GET Example

In this, Spring Boot RestTemplate GET request example, learn to use RestTemplate to invoke HTTP GET API and verify the response status code and the response entity body. To create the rest APIs, use the sourcecode provided in spring boot rest api example. 1. Setup Start with including the latest …

Spring RestTemplateBuilder Example

Learn to use Spring RestTemplateBuilder to create or build RestTemplate bean which can be used to send HTTP requests. 1. Default RestTemplateBuilder To inject RestTemplateBuilder, pass it as a constructor argument in the service class. 2. Custom RestTemplateBuilder To create custom RestTemplateBuilder, create @Bean of type RestTemplateBuilder in Spring context. …

Log Request and Response with Spring RestTemplate

In this Spring boot rest interceptor example, learn to use ClientHttpRequestInterceptor with Spring RestTemplate to log request and response headers and body in Spring AOP style. 1. Spring REST Interceptor Usages We can use this interceptor for many useful tasks. 2. REST Interceptor to Log Requests and Responses Below given …

Configuring HttpClient with Spring RestTemplate

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.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.