Open emmanuel opened 11 years ago
Thanks for the input! It's nice to finally get some outside feedback on this stuff. I saw this a few days ago, but haven't had a chance to give this a serious look yet. I'll try for this weekend though.
No rush.
I've been playing around with Percolator and related to that, I've been peeking around at a few JSON hypermedia content types. There's a lot I like about Hyper+JSON
, but I was excited to see that the link hints draft provides some ideas that could be adapted/adopted.
Also I learned that JSON Schema supports (as of draft 4?) the notion of schema IDs (see tdegrunt/jsonschema and https://github.com/natesilva/jayschema) and $ref
s to schemas of embedded entities, which gave me the idea of something like $ref
to reference a schema by URL instead of inlining it into the response.
Anyways, I'm looking forward to your thoughts.
Ooooh $ref is very cool. I like that. I'm not sure if the jsonschema parser in Percolator supports that, but I definitely think that's a great idea.
I'm curious though what do you think the advantage is of:
"self": { "href": "/musicians", "hints": { "allow": [ "GET" ] } }
... over:
"self": { "href": "/musicians", "method": "GET" } // GET is the default anyway, so usually method is omitted in that case
?
I have a much easier time selling the second one to people that are new to hypermedia apis. Any clue what the hints standard is trying to solve with the more wordy format?
I don't see any benefit other than bundling everything under the hints
key. Frankly I was a bit confused about how to express certain things based on my reading of the hints draft. Specifically I flip-flopped a bit as to how schema URIs should appear. For example, this:
...
"href": "/musicians",
"method": "POST"
"accept-post": { "application/json": { "schema": { "href": "/schemas/create-musician"
}
}
}
...
Feels really wordy to me. I think the schema
key could be moved up to being a sibling of href
and method
(as you had it in the blog post); I am a little uncomfortable with dropping the explicit content type, but I am struggling to satisfactorily answer the question: why would a client need/want to switch content types? My discomfort stems from questions like what is meant by no content-type expectation stated in the link info? does it mean that the client should continue using the current resource's content type? No answers, only questions. :)
I have to admit, I'm not 100% sure what the answer is for different types either. This is why the Percolator code currently allows a "type" property, but I haven't gone into it in the spec. I was thinking that if someone wanted to use schema (or uri-template?) to specify a "application/x-www-form-urlencoded" payload that might be possible too. Or if I wanted to specify a multipart/form-data content-type, or some other format with no schema ( image/jpeg? ) just for general document upload. Those seem like pretty common use-cases (though I haven't personally used Percolator that way YET).
The bottom line though is that IMO you only need a type on requests with a body, just like html forms do (and "application/x-www-form-urlencoded" is the implicit default, which is where I got the idea for an application/json explicit default).
Conversely, GET requests have no need for a type because they have no request body. I didn't intend the type to represent anything other than a request body content-type expectation because Accept headers are perfectly fine for handling response bodies.
I think this could work, but I'd like to try it out before I put it in the spec. What do you think?
I haven't completely thought this through, but:
Hyper+JSON
could benefit from incorporating them.With that in mind, I drafted the following as a proposed refinement to the example on your blog:
This presupposes that the schema accepted for creating a musician can be retrieved at
/schemas/create-musician
, which when requested with anapplication/json
content type, would yield a response like:A couple of notes:
/schemas/create-musician
by joining the linkrel
(create
) with the singular resource name (musician
). I think this is a decent (or even good) default approach for defining schema URIs.hints
key and its layer of nesting could be dropped, which would placeallow
andaccept-post
as siblings of (on the same level as)href
, directly under the linkrel
key.That is all. What do you think?