Reputation: 3265
Let's say we have a RESTful API method:
POST /people
{
"name" : "John",
"_links" : {
"address" : {
"href" : "/addresses/2"
}
}
}
You can see that address
has a link to another resource.
To resolve the address_id
of that resource, should the server:
Break up the URL and identify the "id" part of the route
Even make a curl request to itself, in order to get the address_id
of that linked resource?
Upvotes: 2
Views: 219
Reputation: 10981
I feel, as you probably do, that #2 is the way it should be done, and #1 is just a hack based on internal knowledge. What if the client sent a href that was an absolute URI, http://yoursite.com/addresses/2 would you still want to use #1, and try to detect the ID?
Lets presume your site sends address resource representations with a defined and documented MIME type. What if the client sent a href value pointing to a third-party URI, which also returned responses of that format, and presuming you'd want to support that. You'd have to implement #2 anyway. In that instance there's little reason not to use it for your own (performance being the main one).
To be honest, what I would probably do is go with #1 until the need for #2 arose.
Upvotes: 1