What is the proper way to create entity which will be linked to other ones? I can't find any source about how it should be done or how it is done in Symfony with FOSRestBundle bundle.
Background:
Lets have entity Car with entities of Wheel.
How to create Car with wheels in one request?
url: foo.com/cars POST
data: {car:{name="porsche", wheels:[{name:"fr"}, {name:"fl"}] }}
Is this the proper way how to do it? I read something about LINK and UNLINK http methods, but that would need send multiple requests in order to create all wheels and then link them together.
How to create wheel with belongs to multiple cars?
url: foo.com/wheels POST
data: {wheel:{name="super wheel", cars:[{id:1}, {id:2}] }}
In this situation, maybe using LINK header would be appropriate. But after reading this article, it would require parsing LINK headers for all POSTS and PUTS as well, making it expensive and bulky.
EDIT
I wrote to the author of mentioned article. Here is his answer:
I think you can send data containing both your wheels and cars in a single request. The most important thing here is to be pragmatic. There is no "clear" rules for building REST APIs.
LINK/UNLINK are useful when resources already exist, and you want to "link" them, in >other words, you want to add a "relation" between them, such as friendship for users, for instance.
About your second question, if cars exist, you can, first, create your wheel, and "link" >it to your cars. But it would mean two requests for this action (you can add multiple link headers in one request), or better you could send one POST request with link headers : one request to rule them all :p
Another option would be to reference the cars' ids into your wheel data. I think it's fine to do that too.