Hey Kevin, thanks for clarifying - I have a couple more questions..
Ok, how does one determine whether a the link is considered
On Sat, Jul 7, 2012 at 4:37 PM, Kevin Swiber <ksw...@gmail.com> wrote:
> Hey Mike,
>
> For the sake of comparison, I created a gist with the orders collection
> example from the HAL draft and added a potential JSON Siren equivalent.
> https://gist.github.com/3066768
>
> Where HAL adds customer and basket to the links array, Siren prefers to add
> these to the entities array as embedded links [1].
>
> HAL's _embedded and _links vs. Siren's entities and links: Siren will
> represent links to entities inside the entities array, whereas HAL will put
> this reference in the _links array. Siren's links array prefers rel values
> that are navigational in nature (up, next, previous, first, self, last,
> index, etc.).
"navigational" or not?
What benefit is there in forcing this distinction?
> - Properties of the format should not collide with implementation-providedI think that is a theoretical difference, properties are extremely
> properties
unlikely to collide with _links or _embedded in the case of HAL. The
underscore prefix is arguably even overkill.
> - Entities and actions may have class attributes to describe the nature ofReally not a fan of this approach (it borders on anti-pattern) but, if
> the content in the context of the representation.
you really have to, this is exactly what the "profile" link is
designed for - fwiw this is actually included in the hal+json spec.
> - Action structures are used even for operations such as search, whereas HAL
> utilizes URI templates.
Good catch! Honestly, I didn't document this, because I had some questions on the design that I never fully answered.Prior to publishing the document on GitHub, I had a section that defines a meta object on the root entity.{"meta": {"profile": "http://x.io/docs/slick-api"}}The questions is... Should any other piece of information exist in the meta object? If the answer is no, then this is better represented as a profile property under the root entity. If the answer is yes, what are those properties?
Any thoughts?
On Sat, Jul 7, 2012 at 12:27 PM, Mike Kelly <mikeke...@gmail.com> wrote:It's the difference between communicating options for traversal through the entity graph (via parent-child relationships, for instance) and providing the client options to move through your API "sitemap." Encapsulation is a heavily used concept in Siren. There is an implied ownership with sub-entities that doesn't exist in the links structure. That ownership in HAL would have to be communicated via documentation about the link relation. I believe forcing this distinction actually results in a reduction of complexity via a clearer understanding of the link's context (sub-entity vs. higher level navigation). Do you think there's a disadvantage to this approach?> - Properties of the format should not collide with implementation-providedI think that is a theoretical difference, properties are extremely
> properties
unlikely to collide with _links or _embedded in the case of HAL. The
underscore prefix is arguably even overkill.As long as it's a valid JSON property name, there is the potential for collision. I'm more comfortable making this a non-issue over a "not likely to happen" approach. Just a difference in trade-offs and design. The trade-off for JSON Siren is more verbose syntax with the properties object. I feel that's acceptable.
Be aware that the approach HAL and some others take allows them to be applied to an existing API in a manner that would be backward compatible for clients and thus client could progressively support the new functionality, but with your approach clients of existing APIs would need to be at least somewhat rewritten to still work if the API owner decided to adopt Siren.So my feedback is: for use-cases I care about the explicit 'properties' makes selecting Siren a non starter. Just saying.
that's pretty much the "profile" pattern[1]; quite handy, IMO.
[1] http://gmpg.org/xmdp/
On Saturday, July 7, 2012 at 9:15 PM, Steve Klabnik wrote:
It's per request.
Thanks, Mike. You're absolutely right. Siren, as it is now, does not support building on an existing API and maintaining backwards compatibility. Do you feel strongly that it should be a goal of the project?
To be perfectly honest, it's a use case I didn't even consider. Shifting to a completely new media type is a very large change that I would expect to break an existing API. If such a change was warranted, I would take a different approach, preferring to support multiple media types while having human conversations to discuss a transition strategy for existing clients (assuming these clients' developers are human-reachable, of course. :)
-MikeSiren might be absolutely perfect for your needs so I can't speak to your use-cases, I can only speak to the ones that interest me; Mark Nottingham's "MANY CLIENTS AND ONE SERVER" [1]. But since you requested feedback I assume you were asking for how it applies to our use-cases? If yes, then...What I see is that public APIs are almost always designed for ease of consumption. IMO this is because the more complexity that an API client must process, the less adoption it is likely to see. So most public web APIs publishers support URL construction and really simple JSON responses. I think getting API publishers to support more elaborate media types is an uphill battle. I think people start building APIs by building something that is as simple as possible, and then they grow their APIs in complexity as the number and different types of clients using the API grows.This IMO the best approach is one where the complexity can be optionally layered and grown over time, especially if the complexity can be stored in a discovery document so the existing API isn't changed and only the clients that need more complexity have to interact with it.Lastly, I lament the fact there are so many different competing approaches each with their own one or two advocates; to name a few: HAL, JSON-LD, OData, Object Network, Collection+JSON, JSON Schema plus several others I can't think of at the moment, and now Siren. What I'd really like to see is everyone who's advocating their own approach come together and agree to collaborate on a NEW approach where all the advocates agree up front that the goal is to create a signal approach that can become a standard, and ideally one that can start very simple but evolve to handle more and more complexity as more and more of the web adopts it.If that one standard approach can emerge, then I believe we're likely to see open-source client and server libraries in major web languages/platforms, explorers in browser's developer toolkits, and maybe the equivalent of XMLHttpRequest but for this new standard to be added to all browsers, sooner than later.FWIW. :)
Yes. The problem is I'm probably misusing the term in the way most people use it. What I really mean is to extract the hypermedia control information into a single resource for the API instead of including it in every JSON API response.
Sorry for being a bit dense. :/
LOL! No worries, I have my fair share of being far more dense than that.
I'd love to see a mock of this, see how it would work in an existing API and how it might affect coding clients (if any).
got an example i can check out?
You *would* call me on that, now wouldn't you. :)I started to mock a bit of the Twitter API earlier and realized I didn't know URI Template syntax well enough to get it perfect, but if you are willing to overlook my URI Template errors I could mock up a few resources.Also, as I understand it oData JSON Light[1] can be used this way too, although I've not verified that.
<snip>
I started to mock a bit of the Twitter API earlier and realized I didn't know URI Template syntax well enough to get it perfect, but if you are willing to overlook my URI Template errors I could mock up a few resources.</snip>
first, i think this is a very intriguing idea; i've seen it mentioned, but not seen a working model at runtime, only at design-time.second, for early designs, i wouldn't sweat the details of URI Templates. getting a general layout, a clear way to associate the runtime data representation w/ the proper bits of hypermedia description info, and getting a sense of how it will look to a client dev is more interesting right now.
So I created a really simple document that could exist at a hypothetical "https://api.twitter.com/.well-known/json-api.json" to represent two of the Twitter API resources:-MikeSince I spent 2 hours on this I didn't agonize over the architecture, I just built something to show.Then I started writing an explorer for it in PHP, and remember how difficult it is to write an API explorer in an evening. :) Still, I'm pretty sure the data captured in the json-api.json would be enough to allow the response from the Twitter Search API to be surfed to the status API assuming someone had the time to write the explorer. Hopefully you (mca) or someone else find this idea has value and can push it forward[*].
Then I started writing an explorer for it in PHP, and remember how difficult it is to write an API explorer in an evening. :)
Ok, but a browser for a media type is not something you necessarily
need to (re)implement yourself, it should be re-usable between
applications.
HTML is not a good option for m2m APIs, it's bloated with features
that have no relevance to a machine interface.. using it increases the
challenge of interacting with your app, making it more likely that
people will go elsewhere.
On Sun, Jul 8, 2012 at 5:27 AM, Mike Kelly <mikeke...@gmail.com> wrote:Ok, but a browser for a media type is not something you necessarily
need to (re)implement yourself, it should be re-usable between
applications.True, but why even have to implement it at all?HTML is not a good option for m2m APIs, it's bloated with features
that have no relevance to a machine interface.. using it increases the
challenge of interacting with your app, making it more likely that
people will go elsewhere.You can always restrict yourself (quite successfully) to HTML features that *are* relevant to m2m interactions, and end up with quite concise representations. We are actively doing this, by the way, and it is working well.
Can you talk a little more about your opinion of the relative challenges of:* Bootstrapping a new media type (e.g. Siren or HAL) vs. using a media type with a huge population of people who understand it (HTML)* Getting new developers to download and install a media type explorer vs. having one already installed (web browser)I would assert that the real challenge here is actually getting people to build hypermedia-aware clients. If you don't want to build a hypermedia API, then I agree that HTML doesn't offer you much at all (but then neither do Siren or HAL when compared to plain application/json). If you *do* want to build hypermedia APIs, then I think overlooking a domain-agnostic hypermedia-aware media type with tons of existing tooling and a huge developer population and trying to mint your own is actually the bigger uphill climb.I'll grant that HTML isn't perfect (form support for something other than GET/POST, for example) and there aren't widespread client libraries for treating it as an API...yet. Personally, I prefer to start from HTML and build the (minimal) extra tooling I need while working through the standards bodies to fix its deficiencies over time. There is also the potential for adding the ENTIRE WEB as addressable/linkable surface area from your API, because your clients will already have the basic processing in place for it.
Now, please don't construe this as me saying that Siren or HAL aren't valuable. On the contrary, I think we are pretty far away from understanding what good, easily-adoptable hypermedia APIs look like, so I think there's value in exploring multiple options, because, after all, I might be wrong about using HTML! Really this is more of an attempt to help refine the arguments for using and creating media types like Siren or HAL.
Siren might be absolutely perfect for your needs so I can't speak to your use-cases, I can only speak to the ones that interest me; Mark Nottingham's "MANY CLIENTS AND ONE SERVER" [1]. But since you requested feedback I assume you were asking for how it applies to our use-cases? If yes, then...
What I see is that public APIs are almost always designed for ease of consumption. IMO this is because the more complexity that an API client must process, the less adoption it is likely to see. So most public web APIs publishers support URL construction and really simple JSON responses. I think getting API publishers to support more elaborate media types is an uphill battle. I think people start building APIs by building something that is as simple as possible, and then they grow their APIs in complexity as the number and different types of clients using the API grows.
This IMO the best approach is one where the complexity can be optionally layered and grown over time, especially if the complexity can be stored in a discovery document so the existing API isn't changed and only the clients that need more complexity have to interact with it.
Lastly, I lament the fact there are so many different competing approaches each with their own one or two advocates; to name a few: HAL, JSON-LD, OData, Object Network, Collection+JSON, JSON Schema plus several others I can't think of at the moment, and now Siren. What I'd really like to see is everyone who's advocating their own approach come together and agree to collaborate on a NEW approach where all the advocates agree up front that the goal is to create a signal approach that can become a standard, and ideally one that can start very simple but evolve to handle more and more complexity as more and more of the web adopts it.If that one standard approach can emerge, then I believe we're likely to see open-source client and server libraries in major web languages/platforms, explorers in browser's developer toolkits, and maybe the equivalent of XMLHttpRequest but for this new standard to be added to all browsers, sooner than later.
FWIW. :)
> Just curious, how would you envision using "profile" with JSON? Do you meanhttp://tools.ietf.org/html/draft-wilde-profile-link-01
> using "profile" in the HTTP "Content-type" header like [1], colloquially to
> be like the pattern used by Xhtml Meta Data Profiles, or something else?
application/vnd.huddle.data; version=1; describedby="https://schema.huddle.net/rng/folder.rnc"
This allows machines to understand what you mean and use it in a meaningful way in most cases (usually) without requiring out-of-band information (which is what we want)
On Jul 8, 2012, at 10:55 AM, Steve Klabnik wrote:
On Jul 8, 2012, at 2:30 PM, Mike Kelly wrote:Ok, I think the point that is being made is that referring to it as a'service document' is a poor choice if what you are really talkingabout is a normal resource that provides core navigational links andis traversed over as part of the application itself.
Yes, I think you are correct. I've come to realize "service document" is a bad choice of name given the reaction to the
name here on this list.
Glenn:Very interesting observations, well expressed. I've heard them before and I've not yet seen tangible examples of these burdens that HTML has over other hypermedia types. It would help me if you could show me some comparison examples between your favorite hypermedia type and HTML.Note that I am asking you to compare HTML to one or more hypermedia types, not HTML and vCard."I have to map from HTML elements to a specific domain. "Yes, this happens all the time; every act of crafting a response involve mapping domain specifics to a message format. My Q here is this. what other _hypermedia_ type requires less "squinting" when you are mapping from "X" elements to a specific domain? A great help would be mapping domain specific data to your favorite _hypermedia_ type (NOT vcard!) and then mapping the same data to HTML.
"Try seeing what happens if you rewrite something like say Gmail with passing HTML back and forth for Ajax calls. The bloat matters."Again, I'd like to see comparisons of one of your favorite hypermedia types to HTML in passing back and forth Gmail data. Even a small example that shows how much less "bloat" there is in hypermedia format X over HTML will be helpful.
"But for me the fact that HTML is primarily for layout in browsers and that I "can" bend it to be other things but that it is not inherently, is enough of a deal breaker."What elements in HTML that are layout oriented are you REQUIRED to use when using HTML for APIs? and which of these are better expressed using a hypermedia type of your choosing? IOW, an example that shows the _unavoidable_ layout-burden in an HTML API response vs the same response expressed in hypermedia type X and the elimination of that burden would be helpful.
Howdy, folks!I recently started piecing together a specification of a hypermedia type. I'd love to get your thoughts and ideas for improvement. Many of your conversations here and your related work have been an inspiration.First draft: https://github.com/kevinswiber/sirenI've been working on a Hypermedia API that has gone through several iterations. Siren is a result of my latest efforts.Some of the goals have been to represent, in a meaningful way:- Communication of current state- Embedded resources- Embedded resource links- Navigation links- ActionsI developed Siren with an Entity concept, defined as being URI addressable and containing sub-entities, actions, and navigational links.I have been focusing on JSON Siren as the first implementation, because it fits in nicely with my technology stack (Node.js, CouchDB, Web frontend).Head on over to https://github.com/kevinswiber/siren to take a peek! I'm happy to have discussions, and I'm also open to GitHub Issues and Pull Requests.Thanks!
--
Kevin SwiberProjects: https://github.com/kevinswiber
Twitter: @kevinswiber
It should also be noted that the same link might represent an 'item' in one collection as well as a 'collection' itself. In this case, both link relation values can be applied to the same link: Link: <...>; rel="collection item"; title="A Review of Issac Asimov's Collected Works - Vol. I"
On Mon, Jul 9, 2012 at 1:22 PM, Kevin Swiber <ksw...@gmail.com> wrote:
> "Machines" in this context is really referring to existing JSON parsers. IDo you have any specific examples of libraries that this presents an issue for?
> should have made that clear. JSON parsers often attempt to generate object
> structures in <your language of choice>. Putting a space in a property name
> will get hypermedia implementors into the weeds of how their parser of
> choice handles spaces. (For some languages, this is fine as a valid
> property name. For others, there has to be a workaround.) While an API
> consumer may be perfectly fine handling this scenario, I'd prefer to not
> force it on folks right out of the box. (To be fair, there are other
> characters that may cause issues, as well.)
Two properties with the same name would be invalid JSON, if you have
> Compounding the problem with "named links" is that link rel values may not
> be unique in a collection of links. Think of a family tree representation
> that contains 2 "brother" links on the same element. The way a JSON parser
> handles two values of the same property name will differ across parsers.
multiple links in HAL then you use an array of link objects:
{
"_links": {
"brother": [{
"href": "/people/bob"
},{
"href: "/people/ted"
}]
}
I have a lot of respect for Jon Moore and HTML but… any decent HTML page these days will have a lot of javascript, jquery callbacks, social media tracking and so on… That's fine to render a view targeted to a human. But, if you output a representation for a machine, it may behoove you to use something more appropriate. This could be a bare bone HTML but then why not use XML or JSON? HTML scraping is not a best practice. Simpler may be better.
Would we be in agreement and say:
- Web users are not just humans but more and more machines.
- Hypermedia API is here to stay. No question about it. Machines need to be able to follow links AND understand what they are following. That's the real challenge.
- m2m rendering is a must. Use what is appropriate for your needs but document it in a way that can be used m2m as well. I do not see a way around some kind of a service document and simple schema. We need to use it for our docs and internal validation. It has to stay current as the app evolves over time.
Four things:1.) HTML is notoriously difficult to parse whereas JSON is absolutely trivial to parse in most web languages/platforms. XHTML is easier, but still no where near as easy as JSON is some web languages/platforms.
2.) X/HTML response representations are bloated compared to their JSON equivalent and that's an issue for mobile clients.
3.) HTML didn't really apply here as you referred to my post about a proof-of-concept "service document" that defined rules for processing Twitter's JSON based API, and
4.) Ironically the difficult part of writing the service document was not the display to the use but instead presenting the actions that could be performed by the API. I would have had the exact same difficulty if I had encoded the service document in HTML.
HTML does a have ubiquity on it's side however...I personally find it lacks in usability for an "API". You "can" use it and I can see the benefit of having something easily consumable by a browser. However when I read it / create it for an API I find myself continually squinting and there is a conceptual overhead. I have to map from HTML elements to a specific domain. Wheras if I look at a specific media type with a specific purpose, such as say vcard (Yes it does not support hypermedia, but regardless) then the semantics of the domain are expressed very richly and obviously.
Lastly there is the leanness factor. Like it or not HTML is bloated. Yes there are tons of web servers that work with it etc, but that doesn't change the bloating factor. In the traditional model of request/response for HTML applications did far fewer requests than they do in the apps we are building today. Try seeing what happens if you rewrite something like say Gmail with passing HTML back and forth for Ajax calls. The bloat matters.
But for me the fact that HTML is primarily for layout in browsers and that I "can" bend it to be other things but that it is not inherently, is enough of a deal breaker.
I'll use my example to indicate the friction.The JSON example can simply be read in Javascript, and converted into an object. I can then navigate the graph of the object simple accessing named properties. The one exception are the links which are a generic collection.In the case of the HTML example I either parse manually or I read it into a DOM object. If I go with a DOM object I then have to read a recursive set of nested collections looking at the class/rel to pull out the information.
That to me is an example of the friction that I am talking about.
1000 times easier :). Most importantly, using JSON eliminates a dependency that using HTML would require.And for that dependency I have to worry about if the library will be supported in the future, if killer bugs will be fixed. Plus the objects that result from json_decode($json) are much simpler to process than the ones from file_get_html($json_file) (looking at: http://simplehtmldom.sourceforge.net/ for PHP.)For Javascript, the example is from a 2008 blog post with closed comments and numerous reported bugs, not from an active open-source repository, and there don't appear to be any better options. Plus, I'd have to include it too, rather than just $.getJSON() in jQuery.Take PHP & Javascript and that's about 1/2 of web development (give or take 25%.)Using HTML, which has all its foibles that work well for browsers, is just not a good pick for machine-to-machine web services. IMO anyway.
I think if we ported JQuery selector syntax into other languages, we'd find lots of people who have no problem whatsoever manipulating HTML.
Operative word: "IF" Right? Are there any known plans for this?
You can tell the difference in gzipped formats at small response bodies (where, to be honest, the difference doesn't matter as much), but as the response sizes grow, the compression algorithm helps you more and more, as it asymptotically approaches the actual information theoretical content.
Since I don't do mobile development I don't worry about these things but I'd be really interested to hear what an active mobile developer who deals with high usage apps or apps with large amounts of data transfer would have to say as a counter to what an advocate for HTML would have to say. :) Anyone?
"Or you could use something like JQuery and access the DOM quite elegantly.:If I am running in a browser / or something like node maybe, but there are still PLENTY of native apps ;-)