Skip to content

Commit 2b47b89

Browse files
committed
Added RestTemplate to RestClient migration guide
Closes gh-23269
1 parent 4a10fa6 commit 2b47b89

File tree

1 file changed

+308
-0
lines changed

1 file changed

+308
-0
lines changed

framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,314 @@ See the xref:integration/observability.adoc#http-client.resttemplate[RestTemplat
558558

559559
Objects passed into and returned from `RestTemplate` methods are converted to and from HTTP messages with the help of an `HttpMessageConverter`, see <<rest-message-conversion>>.
560560

561+
=== Migrating from `RestTemplate` to `RestClient`
562+
563+
The following table shows `RestClient` equivalents for `RestTemplate` methods.
564+
It can be used to migrate from the latter to the former.
565+
566+
.RestClient equivalents for RestTemplate methods
567+
[cols="1,1"]
568+
|===
569+
| `RestTemplate` method | `RestClient` equivalent
570+
571+
| `getForObject(String, Class, Object...)`
572+
| `get()
573+
.uri(String, Object...)
574+
.retrieve()
575+
.body(Class)`
576+
577+
| `getForObject(String, Class, Map)`
578+
| `get()
579+
.uri(String, Map)
580+
.retrieve()
581+
.body(Class)`
582+
583+
| `getForObject(URI, Class)`
584+
| `get()
585+
.uri(URI)
586+
.retrieve()
587+
.body(Class)`
588+
589+
590+
| `getForEntity(String, Class, Object...)`
591+
| `get()
592+
.uri(String, Object...)
593+
.retrieve()
594+
.toEntity(Class)`
595+
596+
| `getForEntity(String, Class, Map)`
597+
| `get()
598+
.uri(String, Map)
599+
.retrieve()
600+
.toEntity(Class)`
601+
602+
| `getForEntity(URI, Class)`
603+
| `get()
604+
.uri(URI)
605+
.retrieve()
606+
.toEntity(Class)`
607+
608+
609+
| `headForHeaders(String, Object...)`
610+
| `head()
611+
.uri(String, Object...)
612+
.retrieve()
613+
.toBodilessEntity()
614+
.getHeaders()`
615+
616+
| `headForHeaders(String, Map)`
617+
| `head()
618+
.uri(String, Map)
619+
.retrieve()
620+
.toBodilessEntity()
621+
.getHeaders()`
622+
623+
| `headForHeaders(URI)`
624+
| `head()
625+
.uri(URI)
626+
.retrieve()
627+
.toBodilessEntity()
628+
.getHeaders()`
629+
630+
631+
| `postForLocation(String, Object, Object...)`
632+
| `post()
633+
.uri(String, Object...)
634+
.body(Object).retrieve()
635+
.toBodilessEntity()
636+
.getLocation()`
637+
638+
| `postForLocation(String, Object, Map)`
639+
| `post()
640+
.uri(String, Map)
641+
.body(Object)
642+
.retrieve()
643+
.toBodilessEntity()
644+
.getLocation()`
645+
646+
| `postForLocation(URI, Object)`
647+
| `post()
648+
.uri(URI)
649+
.body(Object)
650+
.retrieve()
651+
.toBodilessEntity()
652+
.getLocation()`
653+
654+
655+
| `postForObject(String, Object, Class, Object...)`
656+
| `post()
657+
.uri(String, Object...)
658+
.body(Object)
659+
.retrieve()
660+
.body(Class)`
661+
662+
| `postForObject(String, Object, Class, Map)`
663+
| `post()
664+
.uri(String, Map)
665+
.body(Object)
666+
.retrieve()
667+
.body(Class)`
668+
669+
| `postForObject(URI, Object, Class)`
670+
| `post()
671+
.uri(URI)
672+
.body(Object)
673+
.retrieve()
674+
.body(Class)`
675+
676+
677+
| `postForEntity(String, Object, Class, Object...)`
678+
| `post()
679+
.uri(String, Object...)
680+
.body(Object)
681+
.retrieve()
682+
.toEntity(Class)`
683+
684+
| `postForEntity(String, Object, Class, Map)`
685+
| `post()
686+
.uri(String, Map)
687+
.body(Object)
688+
.retrieve()
689+
.toEntity(Class)`
690+
691+
| `postForEntity(URI, Object, Class)`
692+
| `post()
693+
.uri(URI)
694+
.body(Object)
695+
.retrieve()
696+
.toEntity(Class)`
697+
698+
699+
| `put(String, Object, Object...)`
700+
| `put()
701+
.uri(String, Object...)
702+
.body(Object)
703+
.retrieve()
704+
.toBodilessEntity()`
705+
706+
| `put(String, Object, Map)`
707+
| `put()
708+
.uri(String, Map)
709+
.body(Object)
710+
.retrieve()
711+
.toBodilessEntity()`
712+
713+
| `put(URI, Object)`
714+
| `put()
715+
.uri(URI)
716+
.body(Object)
717+
.retrieve()
718+
.toBodilessEntity()`
719+
720+
721+
| `patchForObject(String, Object, Class, Object...)`
722+
| `patch()
723+
.uri(String, Object...)
724+
.body(Object)
725+
.retrieve()
726+
.body(Class)`
727+
728+
| `patchForObject(String, Object, Class, Map)`
729+
| `patch()
730+
.uri(String, Map)
731+
.body(Object)
732+
.retrieve()
733+
.body(Class)`
734+
735+
| `patchForObject(URI, Object, Class)`
736+
| `patch()
737+
.uri(URI)
738+
.body(Object)
739+
.retrieve()
740+
.body(Class)`
741+
742+
743+
| `delete(String, Object...)`
744+
| `delete()
745+
.uri(String, Object...)
746+
.retrieve()
747+
.toBodilessEntity()`
748+
749+
| `delete(String, Map)`
750+
| `delete()
751+
.uri(String, Map)
752+
.retrieve()
753+
.toBodilessEntity()`
754+
755+
| `delete(URI)`
756+
| `delete()
757+
.uri(URI)
758+
.retrieve()
759+
.toBodilessEntity()`
760+
761+
762+
| `optionsForAllow(String, Object...)`
763+
| `options()
764+
.uri(String, Object...)
765+
.retrieve()
766+
.toBodilessEntity()
767+
.getAllow()`
768+
769+
| `optionsForAllow(String, Map)`
770+
| `options()
771+
.uri(String, Map)
772+
.retrieve()
773+
.toBodilessEntity()
774+
.getAllow()`
775+
776+
| `optionsForAllow(URI)`
777+
| `options()
778+
.uri(URI)
779+
.retrieve()
780+
.toBodilessEntity()
781+
.getAllow()`
782+
783+
784+
| `exchange(String, HttpMethod, HttpEntity, Class, Object...)`
785+
| `method(HttpMethod)
786+
.uri(String, Object...)
787+
.headers(Consumer<HttpHeaders>)
788+
.body(Object)
789+
.retrieve()
790+
.toEntity(Class)` footnote:http-entity[`HttpEntity` headers and body have to be supplied to the `RestClient` via `headers(Consumer<HttpHeaders>)` and `body(Object)`.]
791+
792+
| `exchange(String, HttpMethod, HttpEntity, Class, Map)`
793+
| `method(HttpMethod)
794+
.uri(String, Map)
795+
.headers(Consumer<HttpHeaders>)
796+
.body(Object)
797+
.retrieve()
798+
.toEntity(Class)` footnote:http-entity[]
799+
800+
| `exchange(URI, HttpMethod, HttpEntity, Class)`
801+
| `method(HttpMethod)
802+
.uri(URI)
803+
.headers(Consumer<HttpHeaders>)
804+
.body(Object)
805+
.retrieve()
806+
.toEntity(Class)` footnote:http-entity[]
807+
808+
809+
| `exchange(String, HttpMethod, HttpEntity, ParameterizedTypeReference, Object...)`
810+
| `method(HttpMethod)
811+
.uri(String, Object...)
812+
.headers(Consumer<HttpHeaders>)
813+
.body(Object)
814+
.retrieve()
815+
.toEntity(ParameterizedTypeReference)` footnote:http-entity[]
816+
817+
| `exchange(String, HttpMethod, HttpEntity, ParameterizedTypeReference, Map)`
818+
| `method(HttpMethod)
819+
.uri(String, Map)
820+
.headers(Consumer<HttpHeaders>)
821+
.body(Object)
822+
.retrieve()
823+
.toEntity(ParameterizedTypeReference)` footnote:http-entity[]
824+
825+
| `exchange(URI, HttpMethod, HttpEntity, ParameterizedTypeReference)`
826+
| `method(HttpMethod)
827+
.uri(URI)
828+
.headers(Consumer<HttpHeaders>)
829+
.body(Object)
830+
.retrieve()
831+
.toEntity(ParameterizedTypeReference)` footnote:http-entity[]
832+
833+
834+
| `exchange(RequestEntity, Class)`
835+
| `method(HttpMethod)
836+
.uri(URI)
837+
.headers(Consumer<HttpHeaders>)
838+
.body(Object)
839+
.retrieve()
840+
.toEntity(Class)` footnote:request-entity[`RequestEntity` method, URI, headers and body have to be supplied to the `RestClient` via `method(HttpMethod)`, `uri(URI)`, headers(Consumer<HttpHeaders>)` and `body(Object)`.]
841+
842+
| `exchange(RequestEntity, ParameterizedTypeReference)`
843+
| `method(HttpMethod)
844+
.uri(URI)
845+
.headers(Consumer<HttpHeaders>)
846+
.body(Object)
847+
.retrieve()
848+
.toEntity(ParameterizedTypeReference)` footnote:request-entity[]
849+
850+
851+
| `execute(String, HttpMethod method, RequestCallback, ResponseExtractor, Object...)`
852+
| `method(HttpMethod)
853+
.uri(String, Object...)
854+
.exchange(ExchangeFunction)`
855+
856+
| `execute(String, HttpMethod method, RequestCallback, ResponseExtractor, Map)`
857+
| `method(HttpMethod)
858+
.uri(String, Map)
859+
.exchange(ExchangeFunction)`
860+
861+
| `execute(URI, HttpMethod method, RequestCallback, ResponseExtractor)`
862+
| `method(HttpMethod)
863+
.uri(URI)
864+
.exchange(ExchangeFunction)`
865+
866+
|===
867+
868+
561869
[[rest-http-interface]]
562870
== HTTP Interface
563871

0 commit comments

Comments
 (0)