That's true still we r using parameterisedTypeReference , it could have been better if just toList() kind of method and let compiler figure out the type
Sadly while the compiler can figure out the type, it doesn't give that info to the method so there's no way at runtime for it to know how to create the individual objects. Having said that, turning something into a List is SUCH a common thing to do that ``".bodyToListOf(Post.class)" or similar would be useful.
Great video! Does the new rest client have a more convenient way to handle concurrent requests than the rest template? One big advantage of the web client compared to the rest template for me was that successive calls can be handled a lot quicker because they dont have to wait for another.
What are the main differences between Rest Client and the Feign client (or Spring Cloud OpenFeign) ? Are there scenario's where one is preferred over the other?
Very good info! How does rest client deals when the external service is unavailable or returns some error? Does rest client support circuit breaker handling?
Hi Dan, perfect timing on this. I wasn't able to get the default header to work, but I did get this to work: ResponseEntity response = restClient.post() .uri("/contacts?email={email}&first_name={first_name}&lists[]={listId}", email, firstName, listId) .header("Authorization", "Bearer " + token) .contentType(MediaType.APPLICATION_FORM_URLENCODED) .retrieve() .toBodilessEntity();
I see two elephants in the room there :) 1 - what about error handling (what are the OK responses in terms of http-status) ? 2 - what about client-load balancing en case there are multiple base URLs ? Can you elaborate on this? I would be super interested.
Great content Dan. Thanks for posting this video. One question, I used to use FeignClient and we have I way to log all the request, response, urls, headers, etc. Do you have any idea how we can do the same with RestClient?
Really cool! Do you know if this new shiny thing has Eureka discovery built in and if that's the case is the authentication stuff passed to the discovered service. Reason for asking, I'm using feign today to call other services (and Eureka) but auth is not passed when using Feign which can be solved uisng an interceptor but it's clunky. I'd rather see that the Rest Client have this built in :-)
Hello Dan, Thanks for wonderfull video, Can you make one video on aws lamda for spring boot database access whether to use orm like hibernate or spring data jpa or spring JDBC which one is best suited
Is there a way to disable SSL verification on the RestClient? Like the TrustAllStrategy for the SSLContext in Apache HttpClient (without having to use the HttpClient as a request factory for the RestClient)
If there is an Authorisation token(oauth - Apigee) API call before the real API call how do we make 2 calls here? Also, if the Api calling is massl, can you show how to implement that with restclient
Is there a way to remove Post record also, or we have to have it with the same structure as on remote REST endpoints that you call with RestClient? (Bc of that body to entity mapping)
Clearly there is big misunderstanding with rest template. I worked with 2 compagnies that decide to replace all rest template/opeinfeign clients with webclient because of the misunderstanding
I have 2 issues using RestClient with Spring Boot 3.2. First one is in the builder I set a baseUrl bit I have to prepend the baseUrl on every get() or post() request but I don't know why - makes no sense to me. The other thing is, when I compile a native build, the application cannot find a HttpMessageConverter for my request object which should be converted to JSON. This works finde with Java 21 but not compiled to a native application. Does anyone know why?
You're missed huge and impotant thing here.. error handling.. not everytime you have data on the other end.. so you have two type of errors, expected ones like 'errorCode': 11, which is not in your regular POJO file.. and unxpected ones like .. gateway error in http response.. 500 errors with something weird in body and last errors without HTTP error like API return always 200 but sometimess like "error": "not found item" intead of item object. Can this annotation handle all the cases?
Sir i have a question I wanted to build a spring book project but i have an issue. I have an author and a book entity. They are related to each other. These 2 are in same microservice. How can i seperate them. I use this rest client but how i related them?
Microservices doesn't mean a separate service for each entity, microservice is fine tuning services that make sense, thin close instead of wide open. Does make sense a author microservice alone? What is it purpose alone? Book can be managed by a microservice alone, and author be part of this microservice because a book must have one or more authors. I don't think you should separate them. Microservices provides high degree of maintainability, you could manage book and author independent of each other, but as they are close related, the cost to maintain the relationship could be greater than to maintain them separated. Each time you search a book and show it to the user, you must show the names of the authors too, you will not show id's of authors instead, right. If the author is a separated microservice than you will have to make extra call just to get author data each time you search for book or just before you present a book to the user.
@@cviniciusm my author has crud operations only. author - book relation is many to one. I use this in entity. I got your idea btw. Thank you very much 🙏
I don't get why anyone would be excited about ANOTHER new HTTP client! There are now hundreds - at least 3 in Spring alone. All because we don't want to use an existing dependency but add it to the more general Spring bloat‽
We need a new JdbcClient video as well!. Anyway the ParametrizedTypeReference stuff is lame a bit to write it still.
Recording today!
Thank you so much, you are a gem
That's true still we r using parameterisedTypeReference , it could have been better if just toList() kind of method and let compiler figure out the type
Sadly while the compiler can figure out the type, it doesn't give that info to the method so there's no way at runtime for it to know how to create the individual objects.
Having said that, turning something into a List is SUCH a common thing to do that ``".bodyToListOf(Post.class)" or similar would be useful.
Thank you for sharing. I like the new Rest Client.
Super excited for this feature! 🙌🏼
Me too!
Thank you! We are re-building some clients, will directly remove the resttemplate with this new restclient to be safe for upcoming Spring updates
RestClient with Declarative Interface client is nice combo.
Great video! Does the new rest client have a more convenient way to handle concurrent requests than the rest template? One big advantage of the web client compared to the rest template for me was that successive calls can be handled a lot quicker because they dont have to wait for another.
What are the main differences between Rest Client and the Feign client (or Spring Cloud OpenFeign) ? Are there scenario's where one is preferred over the other?
I was actually wondering the same. Would be really cool to see a video diving into comparison of those
Very good info! How does rest client deals when the external service is unavailable or returns some error? Does rest client support circuit breaker handling?
I really like the enhancements, now to hopefully get a more elegant solution for ParametrizedTypeReference in a future release.
It's just a limitation of Java.
Do you recommend RestClient to make micro services calls?
Where did you get this spring t-shirt? It's awesome.
Hi Dan, perfect timing on this. I wasn't able to get the default header to work, but I did get this to work:
ResponseEntity response = restClient.post()
.uri("/contacts?email={email}&first_name={first_name}&lists[]={listId}", email, firstName, listId)
.header("Authorization", "Bearer " + token)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.retrieve()
.toBodilessEntity();
I see two elephants in the room there :)
1 - what about error handling (what are the OK responses in terms of http-status) ?
2 - what about client-load balancing en case there are multiple base URLs ?
Can you elaborate on this? I would be super interested.
Hey this is great, so if I wanted to do an Integrated test with @SpringBootTest, I could just use this client directly right ?
never used restclient, used resttemplate before so i will try this now.
Great content Dan. Thanks for posting this video.
One question, I used to use FeignClient and we have I way to log all the request, response, urls, headers, etc. Do you have any idea how we can do the same with RestClient?
Really cool! Do you know if this new shiny thing has Eureka discovery built in and if that's the case is the authentication stuff passed to the discovered service. Reason for asking, I'm using feign today to call other services (and Eureka) but auth is not passed when using Feign which can be solved uisng an interceptor but it's clunky. I'd rather see that the Rest Client have this built in :-)
And Spring Feign client. Is it a good choice too? What is your opinion about? Thank you for the greate video o/
Cool, thanks! What about (1) proxies (2) SSL (self-signed, enterprise CA, ...) (3) error handling ?
Hi Dan, Thats awesome 👍
Would you like to make a vidoe about how to setup and solve comon issue with hikari?
I might miss something. Is the RestClient built on top of OkHttp? The code syntax is almost the same as OkHttp.
With HTTP Interface in place, since you replaced PostService with it, you could remove PostService at the end 😊
Awesome video Dan. Love watching your live demos. As a side question: what theme is it? It's so elegant.
bro, thanks for video. but what about errorHandler, restTemplate had amazing option as ResponseErrorHandler, may be restClient has similar option too?
Hello Dan, Thanks for wonderfull video, Can you make one video on aws lamda for spring boot database access whether to use orm like hibernate or spring data jpa or spring JDBC which one is best suited
how to send token for this
Awesome video, thank you ☺️
Thank you for sharing.
Hey, what's a plugin which help to copletly words?
Cool... another video without headers examples...exactly as hundreds others on YT.. 18 min of pure water... Really useful
.header() on uri() or you can add a defaultHeader( ) to the RestClient.builder()
@@DanVega thanks for your answer. Will you do the video with custom requests?
Is “DeleteMapping” typo while others are Exchange?
Yes, just a typo. Thanks for letting me know.
Is there a way to disable SSL verification on the RestClient? Like the TrustAllStrategy for the SSLContext in Apache HttpClient (without having to use the HttpClient as a request factory for the RestClient)
I am getting a 405 Method not allowed for the methods POST, PUT and DELETE. Only the GET Methods work. Any idea?
In the interface why do you use @DeleteMapping instead of @DeleteExchange?
Just a typo
@@DanVega Since your tests passed, that means we can use MVC annotations in interface declaration?
yeah but this seem not so much different compare to ResponseEntity, does it have better performance ?
Does this provide any support to call APIs with Mtls?
NICE T-SHIRT
Can you please compare with feignclient
If there is an Authorisation token(oauth - Apigee) API call before the real API call how do we make 2 calls here?
Also, if the Api calling is massl, can you show how to implement that with restclient
It's so short comparing to the RestTemplate or WebClient.
Let's record the video about Open Feign declarative client.
How to configure RestClient with OAuth2 to call protected endpoints
Is there a way to remove Post record also, or we have to have it with the same structure as on remote REST endpoints that you call with RestClient? (Bc of that body to entity mapping)
what theme is that?
Clearly there is big misunderstanding with rest template. I worked with 2 compagnies that decide to replace all rest template/opeinfeign clients with webclient because of the misunderstanding
By the way if I'm not wrong rest template is still used in spring security Servlet for oauth2 flow
I have 2 issues using RestClient with Spring Boot 3.2. First one is in the builder I set a baseUrl bit I have to prepend the baseUrl on every get() or post() request but I don't know why - makes no sense to me. The other thing is, when I compile a native build, the application cannot find a HttpMessageConverter for my request object which should be converted to JSON. This works finde with Java 21 but not compiled to a native application. Does anyone know why?
You're missed huge and impotant thing here.. error handling.. not everytime you have data on the other end.. so you have two type of errors, expected ones like 'errorCode': 11, which is not in your regular POJO file.. and unxpected ones like .. gateway error in http response.. 500 errors with something weird in body and last errors without HTTP error like API return always 200 but sometimess like "error": "not found item" intead of item object. Can this annotation handle all the cases?
i love this one
Sir i have a question
I wanted to build a spring book project but i have an issue. I have an author and a book entity. They are related to each other. These 2 are in same microservice. How can i seperate them. I use this rest client but how i related them?
Microservices doesn't mean a separate service for each entity, microservice is fine tuning services that make sense, thin close instead of wide open. Does make sense a author microservice alone? What is it purpose alone? Book can be managed by a microservice alone, and author be part of this microservice because a book must have one or more authors. I don't think you should separate them. Microservices provides high degree of maintainability, you could manage book and author independent of each other, but as they are close related, the cost to maintain the relationship could be greater than to maintain them separated. Each time you search a book and show it to the user, you must show the names of the authors too, you will not show id's of authors instead, right. If the author is a separated microservice than you will have to make extra call just to get author data each time you search for book or just before you present a book to the user.
@@cviniciusm my author has crud operations only. author - book relation is many to one. I use this in entity.
I got your idea btw. Thank you very much 🙏
I don't get why anyone would be excited about ANOTHER new HTTP client! There are now hundreds - at least 3 in Spring alone. All because we don't want to use an existing dependency but add it to the more general Spring bloat‽
I am not excited, I am curious. Just use one that fit your project or your company guidelines.