-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing a resource by ID. #46
Comments
Even though I use Siren, I still maintain a RESTful pattern, so (1) is implied. However, you shouldn't make that part of your documentation as you lose control of the namespace. What if in the future the API has to start using a different hostname, or different path to the resource. By passing the I don't think (2) is correct. I'd use links or sub-entities to navigate around to specific resources. That's a very general response to a general question. Specific use cases can probably be better answered on the google group |
In addition to @apsoto's comments, I'll add how I handle queries. I put an action on a top level entity that supports queries. The response is often an entity with a "query-results" class or something like that. I use sub-entities to contain each result with the specific information needed in that "list item" representation. This works fine for queries that might return multiple results. It does get weird when exactly one or zero results are expected, such as when querying by ID. Sometimes, in this case, I return a 302 status code with a Location header pointing to the discovered entity. Some have mentioned adding support for URI Templates[1] to Siren. This would allow you to have URI parameters on actions. That exact syntax has not yet been discussed. Again, to echo the above statement, this might make for a better topic on the discussion group. :) |
For a LOT more detail on how to build a good resourceful API, including query handling, etc.., see Chapter 8 from "Programming JavaScript Applications" (scroll down for links to the HTML format chapters).
I'm completely in favor of this, and it deserves an issue here, if it hasn't been created, yet. |
I'll try to reiterate over the opinions so far:
To clarify some of my original statements i'll give a really high-level overview of our stack.
Rails is not creating the SapientAPI, Rails is only receiving data from it. Therefore you can imagine how we parse the siren data. Rails makes the request to the SirenAPI, parses the properties of a resource and sends them to the SPA. The SPA then sends the resource ID back to Rails. Rails then queries the SirenAPI for that resource. In this configuration sending the (3) (2) Given a resource ID "should" there be a simple way to filter resources? Is it crazy to imagine something like this: Root of the SirenAPI{
...
"actions": [
{
"name": "get_message",
"method": "GET",
"href": "http://example.com/api/messages",
"title": "Find a specific message",
"type": "application/x-www-form-urlencoded",
"fields": [
{
"name": "id",
"title": "ID of a message",
"type": "NUMBER"
}
]
}
]
} |
IMO, move this to the discussion list. On Tue, Mar 3, 2015 at 3:35 PM, Chason Choate [email protected]
|
At my company we use the siren spec for our API. We've come to an internal disagreement about how resources should be queried by ID. (Maybe this is the improper assumption)
/resources/id
.href
urls around and use those.Can anyone shed some light on this issue?
The text was updated successfully, but these errors were encountered: