4 ms·
The concept of 'RESTful URIs' is common, but it doesn't appear in the original dissertation, and it doesn't make much sense; because of HATEOAS¹, you shouldn't
by icebraining 15y ago
The concept of 'RESTful URIs' is common, but it doesn't appear in the original dissertation, and it doesn't make much sense; because of HATEOAS¹, you shouldn't ever need to know what the URIs are.
> I'm not sure about the hypertext part, because I don't understand what hypertext means here. Is Bitcoinica's interface considered hypertext-driven?
It means that the docs should only have to document a single URI (the entrypoint) and the formats, which should have links to the various parts of the API.
For example, you could have an URI, say 'bitcoinica.com/api'. Then you GET that, and it returns a JSON file with the following key/value:
"ticker": "http://bitcoinica.com/api/ticker"
Now the client knows how to get to the Ticker. Then you GET that, and you receive a new list:
{ "btc-dlr" : "http://.../api/ticker/btc-dlr", "btc-eur": "http://.../apu/ticker/btc-eur", ...
Now the client knows how to request a certain currency pair.
This means the URLs can change without breaking all the existing clients.
In general, I'd say this is "kind-of" RESTful. It doesn't follow HATEOAS and it uses custom formats² (it's inevitable, since there's no standard for this). Having URLs for each concept and reusing HTTP methods and auth is RESTful, though.
¹ Hypermedia as the Engine of Application State
² JSON and XML aren't really formats, they're more like transport mechanisms. Formats are KML, MathML, atom, etc.
The point is that knowing it's XML or JSON tells you nothing, your clients are still completely tied to their API. It's just nice not having to write a parser, but it's not a standard format.
- DougWebb 15y agoI understand the appeal of using json, but it doesn't support hyperlinks. There really ought to be a hyperlink datatype as part of the json standard, with the same attributes that html supports: a label, href, rel, maybe more. The label is human-readable, and rel is machine-readable; both provide the semantic information that identifies what the link is for. The url is given by href, of course. Not having this datatype is a big drawback of json for RESTful responses. That's why I typically design APIs to use xhtml responses instead. They're just as parsable (just a big bit slower) but they're richer and they allow the API to be tested with a browser that has no knowledge of the semantics of the API. I consider the ability to use the API using a generic client to be a good test of properly implementing HATEOAS.
- swah 15y agoWhy would an URL type be useful? If JSON responses are {key:value,...}, in both ends 'key' has a meaning, and when you receive {'link':'http://... http://...}, you deal with 'link'... I'm confused.
- DougWebb 15y agoIt would be useful because it would provide a standard way of expressing a hyperlink. URLs are a standard way of expressing the location of a resource, HTTP is a standard mechanism for interacting with resources, but there are no widely-used standards for expressing "here's a URL". XLink and RDF tried to become standards for that, but they haven't caught on. The text/html content type (and its close relatives) are widely understood and include a couple of syntaxes for different types of links, and that's why I like xhtml as my API content type. If JSON had a standard widely understood syntax for links I'd happily switch over since JSON is certainly more popular as a RESTful API content type. Imagine where we would be if every website expressed links using a different syntax, and browsers had to be explicitly programmed to understand a given website's syntax in order to use its links. The web couldn't exist that way.
- icebraining 15y agoXHTML is great for web pages, but it's a poor format if you want to transmit very structured data. There's no way in X(HTML) to say "this is a user", "this is user X's name", "this is user X's email address", etc. Frankly, if I GET an URL from your API describing a certain user's profile, and I get a blob of unstructured text, I won't use your service for long. XHTML + RDFa is a different case, but that's hardly well understood, especially the specific ontologies. It's really no better ATM than using a custom JSON based format.
- DougWebb 15y ago<div data-role="user"> <span data-role="name">...</span> <span data-role="email">...</span> </div> In general, I agree with you that XHTML isn't a great format for structured data. One advantage that XML has over JSON is the ability to attach attributes to data elements. I find that useful, and much easier to use than JSON's best alternative which is to turn a simple data element into a dictionary object. { key: "value" } { key: { attr1: "attr1val", attr2: "attr2val", value: "value" } } <div>value</div> <div attr1="attr1val" attr2="attr2val">value</div> In the XML markup, you can retrieve the value the same way in both cases. With the JSON markup you have to use different syntax to retrieve the value depending upon whether or not there are attributes, which means you'll wind up always using nested objects if the attributes are optional, just to have consistent syntax. What's odd about this is that in Javascript, attributes (aka Properties) can be attached to anything. You want your string variable to have some properties? No problem. You want some of those properties to be functions? Go for it. You want your function to have methods? Enjoy. I'm surprised that JSON didn't include this capability, since it exists in Javascript and is also a big distinguishing factor between JSON and XML. Getting back to hyperlinks as a datatype, JSON uses "" for strings, [] for lists, {} for dictionaries/objects, and key: value for key/value pairs. Why not add <...> for hyperlinks as a special kind of string? The ... could just be a url, or it could be a url followed by a comma-separated list of standard attributes like rel="..." and label="...". It's a small addition, but I think if it was right there in the markup syntax it would become widely used, and software which parses and works with JSON could depend upon it being there and build higher-level functionality on top of it.