0

In Spring Data Rest you can POST something like this to the table product_material which references product and material:

{
"product": "http://localhost:8080/api/products/70bdd2a0-3548-4158-b378-71850c4c1eb3",
"material": "http://localhost:8080/api/materials/1"
}

How can i implement this instead of using product's and material's id?

La Hai
  • 113
  • 2
  • 12

1 Answers1

1

You cannot do it using hateos cause the post request will try to link these child entities using the link you provided "http://localhost:8080/api/materials/1"

the other option is to put the whole entity, but it also will not succeed without providing the id, it will rather create a new entity.

After issuing the "post" request, it will first search for the ID or maybe also the version, if you provided one, and if nothing found it will create a new child entity

Amr Alaa
  • 545
  • 3
  • 7
  • thank you sir. using id is fine with me, just curious how spring data rest does it. – La Hai Nov 01 '20 at 08:27
  • Can you answer this question of mine too, i would really appreciate it! [How to make HATEOAS render empty embedded array](https://stackoverflow.com/questions/64630041/how-to-make-hateoas-render-empty-embedded-array) – La Hai Nov 01 '20 at 08:40