Reputation: 752
I develop rest api and think about following task. I need to post a vehicle entity and bind existing driver to it. What is the common approach to format json for such request? I choose one of these variants, but maybe there are better solutions:
1. {"model":"Corolla","number":"12345", "driver": {"id": 5}}
2. {"model":"Corolla","number":"12345", "driver": {"id": 5, "name": "John"}}
3. {"model":"Corolla","number":"12345", "driverId": 5}
The question is about how to pass information about already created driver entity with known id.
Upvotes: 0
Views: 55
Reputation: 26137
You have to use a hypermedia type, e.g. with HAL+JSON you do it this way:
{
"model":"Corolla",
"number":"12345",
"_embedded": {
"driver": {
"name": "John",
"_links": {
"self": {
"href": "/drivers/5"
}
}
}
},
"_links": {
"self": {
"href": "/models/corolla"
}
}
}
Upvotes: 2