Spring HTTP Interface Clients: Consuming HTTP services in Spring Boot
Vložit
- čas přidán 5. 08. 2024
- In this tutorial you will build out a full REST API using Spring MVC. Next you will learn how to call that service by creating an Http Interface client in a separate service.
The Spring Frameworks lets you define an HTTP service as a Java interface with HTTP exchange methods. You can then generate a proxy that implements this interface and performs the exchanges. This helps to simplify HTTP remote access and provides additional flexibility for to choose an API style such as synchronous or reactive.
00:00:00 Introduction
00:01:34 Creating new projects in IntelliJ
00:03:29 Setting up the Article Service
00:04:47 Setting up the Content Service
00:06:38 Defining the Article class
00:08:47 Creating the API for the Article service
00:13:42 Setting up the Article client
00:16:11 Testing the endpoints manually
00:18:05 Implementing the HTTP Interface client
00:21:34 Adding new methods to the client
00:23:12 Creating the Content Controller
00:25:17 Testing the client's methods
00:27:30 Review and Conclusion
🔗Resources & Links mentioned in this video:
GitHub Repository: github.com/danvega/http-inter...
👋🏻Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/danvega
LinkedIn: / danvega
Newsletter: www.danvega.dev/newsletter
SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️ - Věda a technologie
Sorry everyone for the repository being private but I have made it public and should be accessible now.
Great content! Thanks a lot and keep them coming Dan!
Thank you Aleksandar!
Great content Dan aa ever!! Keep itnup.
Can you do a video on how to use the different annotations in Spring Boot 3 and the different packages such as controller, model and repository?
good video. I hope that you will make video on error handling and resiliency in Http Client.
I'd probably have another interface like ArticleOperations and have the controller implement it and the ArticleClient extend it. Just to keep the contract locked in a bit more and less "discovery". Would/will be nice when Spring starts adding more compile time annotation processing. Can't beat Micronaut HTTP clients. Good video, as usual.
Awesome
How to attach OAuth token for HTTP Interface client request as bearer.
What about error handling? if the articles-service returns server error or anything unexpected?
Please make video on spring cloud circuit breaker pattern concept and implementation by not using Hystrix. Thanks Dan.
1.) Do you have a tutorial on the blocking/non-blocking topic?
2.) How can I log the response body for debugging for failing requests?
Great stuff! How about Exception Handling, getting Headers etc? Need to create the Client at runtime. Questions over Questions :D Interesting content!
Can you please do a tutorial on exception handling when using HTTP exchange
Most important!
how do you dynamically add headers to the Post Requests, for instance, authentication header
What is the background (the picture with all the items showing on the leftside) comes from? My IntelliJ does not have this
I am going to create a client for Github's Rest API, so I need to pass the user's Bearer tokens, so how do we do that ? , as on every call it would be having user specific tokens.
82nd...Thanks Dan
Can you tell us, ho you would structure the model? You need the exact same model in two different applications. How can you make sure it's the same in all you applications?
One thing that I don't like is to copy the Article type. Instead, we could have the client and dto types served as a library by the article service. Like a side car library that is produced by it's service.
It depends... If these are microservices they should be independently deployable and therefor we should be sharing that between services.
@@DanVegaCould you explain this concept better with an example? Thank you very much
Is there a way to set different timeouts for different HTTP Interface methods?
how to do this using open api?
Is it possible at some point to have jdbc interface clients, mongodb interface clients, redis interface clients, Kafka interface clients, testContainer interface clients and so on ?
Really nice!! Is there any benefits use this interfaces, instaed of using Feign?!
This is built into the framework and you don't need to pull in another dependency.
I have a unrelated question. What's your mic and holder? I want to update my setup and I like it, but didn't know the device.
I have the Shure MV7 microphone and the stand is from Elgato.
hi thanks for sharing this great videos but i think it should get better if u use bigger font.tnx man ;)
Amazing content as always, Thanks for that. When I tried to access the git repo it shows a 404.
I have a couple of questions, Where reactive dependencies are used? I couldn't see. I still don't like the idea of using both web and reactive, it can be difficult to explain in an enterprise project, is there anything planned to include on spring web?
What if I use some authentication for endpoint, how should I do it?
The repo should be available now
The reactive dependency is to use the web client and right now we have no way around that.
Can you make a video about spring cloud gateway and key cloack authenticaton ? Thanks.
Great video! Btw why the github repository is non-existant?
Should be fixed now, sorry.
Thanks ! what is the benefit of this approach?? we could also create interface and inject it and then springboot will pick up its implementation at run time
Spring is actually creating the implementation at runtime for you that will talk to the service as opposed to you having to write the low level code to talk to a service.
Hey @DanVega , can you give an example where the value for the @PostExachange is taken from yaml, because for me it is not able to fetch the config from application.yaml
would it help to turn on and off the application?
firstly thanks Dan! also i noticed you created a http file, then all the endpoints are generated. i did the same but it is just an empty file. does this only works in ultimate edition? TIA!
They were not generated, I pasted in that code so you didn’t have to watch me type it out.
@@DanVega still i copy a sample request but still ntg happened. looks like not available for community edition
@@norulshahlamjohn1140 yes I believe I mentioned that but I think it’s an ultimate edition feature. You can test the api using command line or postman
I've always thought it is not good to use both Spring web and Spring reactive web. Is my assumption wrong?
http interface is compatible with graphql ?
How can we use @RequestParam in client interface?
Hi, Dan! But how can we consume pageable data from API?
One can get a cursor and get request the next or prev items in relation to the cursor
Great video i can use this aproch with jwt or passport?
Yes, absolutely I did another video on passing headers for a single request or for every request.
@@DanVega thanks I Will check this video
It looks like feignclient with more code😅. Except for managing non blocking and blocking calls with the type, i don't see the gain. But thanks for your video it s interesting
This is built into the framework and you don't need to pull in another dependency.
What theme do you use for idea IDE?
Same question
I did a video here on my IntelliJ setup czcams.com/video/g78is10FjF0/video.html