• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

how to use WebClient to get a collection of results (HAL, HATEOAS)

 
Rancher
Posts: 184
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm wondering if somebody could help me

I have a Crud repository that exposes the following method:



the result when use Postman looks like this:



I try to get the Price using WebClient but I'm stuck, that's what I have so far but I guess it's wrong as it just creates Price with null fields:





 
Saloon Keeper
Posts: 12878
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your API is not RESTful. URLs are supposed to identify resources, not operations. "Find by vehicle ID" is an operation, not a resource. I'd expect an URL like "/prices?vehicleId=2" or "/vehicles/2/price".

You're also no using HATEOAS correctly. The point is that except for the entry point of your API, you don't build URLs on your client side. You navigate by using the links returned from the service. You should have gotten a link to your endpoint in a previous operation.

Anyway, none of that has to do with your problem. Can you show use the Price class that the client uses?
 
Adrian Grabowski
Rancher
Posts: 184
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
You're also no using HATEOAS correctly.



I suspected that this might be the case Let's start from scratch because I think I made a total mess of it.

I should probably start with the requirement: "The Pricing Service API is converted to a microservice with Spring Data REST, without the need to explicitly include code for the Controller or Service."

So I included spring-data-rest dependency that exposed the REST API.

Price class that client uses looks like this (accessor methods omitted):



So now, I'm able to hit http://localhost:8082/prices/

Which gives me a list of prices:



I can also access any resource by id, no problem.

Now, I wanted to find all the prices with a particular vehicleId so I added that findByVehicleId method to the PriceRepository (I thought that that's the way I need to do it) and now http://localhost:8082/prices gives me the following result:



http://localhost:8082/prices/search shows my query method:

I'm probably barking at the wrong tree, just trying to follow a course on Udacity but it's very confusing as the examples are very basic and the assignment is completely different.

Starter code has this client class (link to github)



But I have no idea what to do to make it work with query parameters





 
Stephan van Hulst
Saloon Keeper
Posts: 12878
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll see if I can make a simple working example later this week.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic