So let's say I have an existing application that has two endpoints /people and /pants. Calling GET /people returns:
[
{
"name":"john",
"age":37,
"pants":[
{
"color":"green",
"brand":"levis",
"size":"medium"
},
{
"color":"indigo",
"brand":"jncos",
"size":"medium-with-huge-legs"
}
]
},
{
"name":"june",
"age":23,
"pants":[
{
"color":"pink",
"brand":"gap",
"size":"small"
}
]
}
]
If i were to use Spring Data Rest and call GET /person i'd receive something like:
{
"_links":{
"next":{
"href":"http://myapp.com/people?page=1&size=20"
},
"self":{
"href":"http://myapp.com/people{&page,size,sort}",
"templated":true
},
"search":{
"href":"http://myapp.com/people/search"
}
},
"_embedded":{
"people":[
{
"name":"john",
"age":37,
"_links":{
"self":{
"href":"http://myapp.com/people/john"
},
"pants":{
"href":"http://myapp.com/people/john/pants"
}
}
},
{
"name":"june",
"age":23,
"_links":{
"self":{
"href":"http://myapp.com/people/june"
},
"pants":{
"href":"http://myapp.com/people/june/pants"
}
}
}
]
}
}
Let's say I have a bunch of existing clients that I don't want to have to change - is there any way to disable the hypermedia portions of the response in some cases (say Accept="application/json") but enable it them for others (Accept="hal+json")?
Thanks!
Updated
Okay - so it appears that much to my chagrin, what I'm looking to do is not supported. I understand why Spring Data Rest is strongly leaning toward Hypermedia... but I don't buy that providing the capability to "disable" hypermedia based on a header thus providing more options is a bad thing.
That aside, I'm a bit unsure of how to actually achieve this via my own Controllers. If I create a Controller and attempt to override the /people
RequestMapping with produces = "application/json" I am able to get the "raw" json back with Accept="application/json" but if I pass
Accept="application/hal+json"` I get a 406 with "Could not find acceptable representation". It looks like the SDR resource mappings aren't mapped with a content type ... any suggestions?