Spring HTTP Interface Clients: Consuming HTTP services in Spring Boot

Sdílet
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

Komentáře • 57

  • @DanVega
    @DanVega  Před rokem +3

    Sorry everyone for the repository being private but I have made it public and should be accessible now.

  • @AleksandarT10
    @AleksandarT10 Před rokem

    Great content! Thanks a lot and keep them coming Dan!

    • @DanVega
      @DanVega  Před rokem +1

      Thank you Aleksandar!

  • @flyinghorse2739
    @flyinghorse2739 Před rokem +1

    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?

  • @ashishsengar87
    @ashishsengar87 Před rokem +1

    good video. I hope that you will make video on error handling and resiliency in Http Client.

  • @GreggBolinger
    @GreggBolinger Před rokem +1

    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.

  • @wagnerfaria1601
    @wagnerfaria1601 Před 5 měsíci

    Awesome

  • @Anbu_Sampath
    @Anbu_Sampath Před rokem +3

    How to attach OAuth token for HTTP Interface client request as bearer.

  • @kyriakosmandalas2121
    @kyriakosmandalas2121 Před rokem +3

    What about error handling? if the articles-service returns server error or anything unexpected?

  • @praveens2272
    @praveens2272 Před rokem +3

    Please make video on spring cloud circuit breaker pattern concept and implementation by not using Hystrix. Thanks Dan.

  • @derBobby2
    @derBobby2 Před rokem +2

    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?

  • @Nico-ly7lh
    @Nico-ly7lh Před 4 dny

    Great stuff! How about Exception Handling, getting Headers etc? Need to create the Client at runtime. Questions over Questions :D Interesting content!

  • @vistakb
    @vistakb Před rokem +3

    Can you please do a tutorial on exception handling when using HTTP exchange

  • @softcoda
    @softcoda Před rokem

    how do you dynamically add headers to the Post Requests, for instance, authentication header

  • @lindayang3203
    @lindayang3203 Před 10 měsíci

    What is the background (the picture with all the items showing on the leftside) comes from? My IntelliJ does not have this

  • @mananmistry7739
    @mananmistry7739 Před rokem

    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.

  • @jopadjr
    @jopadjr Před rokem +1

    82nd...Thanks Dan

  • @viktorreichert9346
    @viktorreichert9346 Před 11 měsíci

    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?

  • @blipintime1543
    @blipintime1543 Před rokem +3

    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.

    • @DanVega
      @DanVega  Před rokem +1

      It depends... If these are microservices they should be independently deployable and therefor we should be sharing that between services.

    • @dnlnfr
      @dnlnfr Před rokem

      ​@@DanVegaCould you explain this concept better with an example? Thank you very much

  • @rajapanda832
    @rajapanda832 Před rokem

    Is there a way to set different timeouts for different HTTP Interface methods?

  • @nattyvegan4288
    @nattyvegan4288 Před rokem +2

    how to do this using open api?

  • @heyyrudyy404
    @heyyrudyy404 Před rokem

    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 ?

  • @rafaband
    @rafaband Před rokem +1

    Really nice!! Is there any benefits use this interfaces, instaed of using Feign?!

    • @DanVega
      @DanVega  Před rokem

      This is built into the framework and you don't need to pull in another dependency.

  • @mars3142
    @mars3142 Před rokem +1

    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.

    • @DanVega
      @DanVega  Před rokem

      I have the Shure MV7 microphone and the stand is from Elgato.

  • @muhammadhooshangi3741
    @muhammadhooshangi3741 Před 11 měsíci

    hi thanks for sharing this great videos but i think it should get better if u use bigger font.tnx man ;)

  • @andreibalzan
    @andreibalzan Před rokem +1

    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?

    • @DanVega
      @DanVega  Před rokem

      The repo should be available now

    • @DanVega
      @DanVega  Před rokem

      The reactive dependency is to use the web client and right now we have no way around that.

  • @ahmetcihan8025
    @ahmetcihan8025 Před 11 měsíci

    Can you make a video about spring cloud gateway and key cloack authenticaton ? Thanks.

  • @anderfolgfu7300
    @anderfolgfu7300 Před rokem +1

    Great video! Btw why the github repository is non-existant?

    • @DanVega
      @DanVega  Před rokem

      Should be fixed now, sorry.

  • @lonesareer
    @lonesareer Před rokem +1

    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

    • @DanVega
      @DanVega  Před rokem

      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.

  • @lalittyagi1765
    @lalittyagi1765 Před 11 měsíci

    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

    • @ChrisB_Crisps
      @ChrisB_Crisps Před 10 měsíci

      would it help to turn on and off the application?

  • @norulshahlamjohn1140
    @norulshahlamjohn1140 Před rokem +1

    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!

    • @DanVega
      @DanVega  Před rokem

      They were not generated, I pasted in that code so you didn’t have to watch me type it out.

    • @norulshahlamjohn1140
      @norulshahlamjohn1140 Před rokem +1

      @@DanVega still i copy a sample request but still ntg happened. looks like not available for community edition

    • @DanVega
      @DanVega  Před rokem

      @@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

  • @felixnjunge78
    @felixnjunge78 Před 9 měsíci

    I've always thought it is not good to use both Spring web and Spring reactive web. Is my assumption wrong?

  • @marciocesar5782
    @marciocesar5782 Před rokem

    http interface is compatible with graphql ?

  • @ElChampi0
    @ElChampi0 Před 11 měsíci

    How can we use @RequestParam in client interface?

  • @ElChampi0
    @ElChampi0 Před 11 měsíci

    Hi, Dan! But how can we consume pageable data from API?

    • @ChrisB_Crisps
      @ChrisB_Crisps Před 10 měsíci

      One can get a cursor and get request the next or prev items in relation to the cursor

  • @gallardofabian
    @gallardofabian Před 11 měsíci +1

    Great video i can use this aproch with jwt or passport?

    • @DanVega
      @DanVega  Před 11 měsíci

      Yes, absolutely I did another video on passing headers for a single request or for every request.

    • @gallardofabian
      @gallardofabian Před 11 měsíci

      @@DanVega thanks I Will check this video

  • @scerrisebastien
    @scerrisebastien Před rokem +1

    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

    • @DanVega
      @DanVega  Před rokem +1

      This is built into the framework and you don't need to pull in another dependency.

  • @yukipuki2224
    @yukipuki2224 Před rokem

    What theme do you use for idea IDE?

    • @angquoctrung6739
      @angquoctrung6739 Před rokem

      Same question

    • @DanVega
      @DanVega  Před rokem

      I did a video here on my IntelliJ setup czcams.com/video/g78is10FjF0/video.html