Loading tutorials
RestClient is Spring's synchronous HTTP client with a fluent API. It arrived in Spring Framework 6.1 and is available in Spring Boot 3.2 and later. This chapter covers what it is, how a request passes through it, and how it relates to the classes you may already know. A working first call at the e6 min readRestClient and how to set the defaults it applies to every request. It assumes you know Java 17 (records, lambdas), Spring Boot basics (beans, @Configuration, injection), and HTTP methods, status codes, and headers. Sending requests and reading responses come i5 min readRestClient call starts by describing where the request goes. This chapter covers the uri(...) methods, URI templates, query parameters, base URLs, and the encoding rules that decide what ends up on the wire. It assumes you can already create a RestClient with a base URL (previous chapter5 min read@Configuration class and inject beans. It also assumes you know Java records and can read a JSON document. You should already have a RestClient built with a base URL, as in the previous chapters. Here you will turn the HTTP response into Java obje6 min readRestClient with a base URL (see "Creating and configuring a RestClient"). It also assumes you know how retrieve() reads a response. You should know the HTTP sem6 min readRestClient from the Spring Boot RestClient.Builder, send a GET request, and map the JSON body to a record. It also assumes you know the HTTP status code classes: 2xx success, 4xx client error, 5xx server error. Here you will see what RestClient does when a 5 min readRestClient with a base URL and send a GET request. It also assumes Java 17 or later and basic Spring Boot configuration. Here you will learn how RestClient decides which HTTP library to use, how to choose one on purpose, and how to set connect and rea6 min readRestClient from the Spring Boot RestClient.Builder (see the chapter on creating a client). You should also be comfortable with lambdas and Spring bean configuration. By the end you will be able to add cross-cutting behavior such as authentication, logging and6 min readRestClient with a base URL, send GET and POST requests, and map JSON to records. It also assumes you know what @Configuration and @Bean do in Spring Boot. If any of that is unfamiliar, review the chapters on creating a client and reading responses first.6 min readRestClient without a network or a real server. It assumes you can read the RestClient calls from the earlier chapters and know JUnit 5 and AssertJ. It also assumes you know what a Spring test slice is.5 min readretrieve() method covers most calls. You describe the request, ask for the body, and let RestClient turn error statuses into exceptions. Sometimes that is too little control. You may need to branch on the status code without throwing, read a response header, stream a large body to disk, or b6 min read