You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use this https://start.spring.io/#!type=maven-project&groupId=com.example&artifactId=consuming-rest&name=consuming-rest&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.consuming-rest&dependencies=web[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
24
+
You can use this https://start.spring.io/#!type=gradle-project&language=java&packaging=jar&groupId=com.example&artifactId=consuming-rest&name=consuming-rest&packageName=com.example.consuming-rest&dependencies=spring-restclient[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
25
25
26
26
To manually initialize the project:
27
27
28
28
. Navigate to https://start.spring.io.
29
29
This service pulls in all the dependencies you need for an application and does most of the setup for you.
30
30
. Choose either Gradle or Maven and the language you want to use.
31
-
. Click *Dependencies* and select *Spring Web*.
31
+
. Click *Dependencies* and select *HTTP Client*.
32
32
. Click *Generate*.
33
33
. Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.
34
34
@@ -69,8 +69,8 @@ that looks something like this:
69
69
That is easy enough but not terribly useful when fetched through a browser or through curl.
70
70
71
71
A more useful way to consume a REST web service is programmatically. To help you with that
72
-
task, Spring provides a convenient template class called {RestTemplate}[`RestTemplate`].
73
-
`RestTemplate` makes interacting with most RESTful services a one-line incantation. And it
72
+
task, Spring provides a convenient template class called {RestClient}[`RestClient`].
73
+
`RestClient` makes interacting with most RESTful services a one-line incantation. And it
74
74
can even bind that data to custom domain types.
75
75
76
76
First, you need to create a domain class, a Java record class or Kotlin data class, to contain the data that you need.
@@ -135,10 +135,8 @@ Now you need to add a few other things to the `ConsumingRestApplication` class t
135
135
show quotations from our RESTful source. You need to add:
136
136
137
137
* A logger, to send output to the log (the console, in this example).
138
-
* A `RestTemplate`, which uses the Jackson JSON processing library to process the incoming
139
-
data.
140
-
* A `CommandLineRunner` that runs the `RestTemplate` (and, consequently, fetches our
141
-
quotation) on startup.
138
+
* A `CommandLineRunner` that builds a `RestClient` instance with the auto-configured `RestClient.Builder`
139
+
and uses it to fetch our quotation on startup.
142
140
143
141
The following listing shows the finished `ConsumingRestApplication` class:
0 commit comments