3 ms·
I can run a regex to find <a> tags as well as the next guy[1] but what do those links mean? Is one of those links a link to delete the object I am viewing and
by munk-a 4y ago
I can run a regex to find <a> tags as well as the next guy[1] but what do those links mean? Is one of those links a link to delete the object I am viewing and one of them a link to update it? What about the link to get a list of all the foos associated with this particular bar? How am I supposed to parse this blob of HTML programmatically to figure out which link is mapped to which action?
I think this is where I think the big failing of original REST comes into play - these self-discoverable actions are sort of impossible to actually leverage... either you're hardcoding some information about the format (i.e. look for the <a class='delete'>) or you're automatically deriving the link anyways... there isn't really a reasonable way for REST to work where these links are self-descriptive enough for a machine to figure out on their own so... in the end... why not just separate that information out into a nicely formatted API document that the devs can have on hand while building their interoperable tool?
1. And personally prefer to always parse my HTML with regexes of course...
- bmn__ 4y ago> what do those links mean? […] figure out which link is mapped to which action The meaning is expressed by the link relation, see <https://news.ycombinator.com/item?id=32155744 https://news.ycombinator.com/item?id=32155744>. > Is one of those links a link to delete the object I am viewing and one of them a link to update it? Sure, see RFC 5023 § 11.1. > What about the link to get a list of all the foos associated with this particular bar? Okay, custom link relations since the existing predefined ones are insufficient. Because `foo` and `bar` are vague, I have to make up some details and can show one way to do it: GET /bar/this-particular HTTP/1.1 Host: munk-a.example HTTP/1.1 200 OK Link: </ns-rel/bar>; rel="type" Link: </collection/foo?filter=/bar/this-particular>; rel="/ns-rel/foo"; title="list of all the foos associated with this particular bar" Link: </bar/this-particular>; rel="self" Link: </collection/bar>; rel="collection /ns-rel/bar"; title="list of all bars" Content-Type: application/octet-stream … GET /collection/foo?filter=/bar/this-particular HTTP/1.1 Host: munk-a.example HTTP/1.1 200 OK Link: </ns-rel/foo>; rel="type" Link: </foo/some>; rel="item /ns-rel/foo"; title="some foo" Link: </foo/another>; rel="item /ns-rel/foo"; title="another foo" Link: </collection/foo?filter=/bar/this-particular>; rel="self start" Link: </collection/foo?filter=/bar/this-particular;page=2>; rel="next" Link: </collection/foo?filter=/bar/this-particular;page=11>; rel="last" Content-Type: multipart/mixed … > impossible […] there isn't really a reasonable way I'm skipping over the rant in the second paragraph which is clearly based on misunderstanding of the subject matter. Instead of baseless assertions, stick to asking questions if you don't want to make HN readers think you're an ignorant fool.