4 ms·
So what if you want to have a list of pages to jump to - send back 80 links? What is a client supposed to do when a new "nextToLast" appears? I've yet to hear
by MichaelGG 14y ago
So what if you want to have a list of pages to jump to - send back 80 links?
What is a client supposed to do when a new "nextToLast" appears? I've yet to hear of any API consumer that is driven like a browser.
What's the actual point, other than some purity to some abstract concept? Just make it part of the API to take /api/things?page=x and do the right thing.
What's "tomorrow it may well be a computer" supposed to mean? We'll have AI? Or there will be some sort of new WSDL "... for REST" invented?
- rtuck 14y agoAbout the pagination example you mentioned: Rather than use link relations, pagination might be better done with URI Templates. This is a spec [1] that allows passing a URI with placeholders to the client which can then fill them in without every option being described up front by the server. It's still a new-ish area but there are library implementations for most major languages now. Explicit link relations aren't the only way to do hypermedia and the best practices are still moving/being discovered. [1] http://tools.ietf.org/html/rfc6570 http://tools.ietf.org/html/rfc6570
- steveklabnik 14y ago> What's the actual point, other than some purity to some abstract concept? The actual point is decoupling. It's generally considered in software architecture that design that's decoupled is a little harder to build upfront, but survives change over time. As a 'real life' example, because Twitter exposed internal details (a tweet ID), clients sorted based on that number, because they assumed it'd be monotonically increasing. Once sequential IDs became a problem with Twitter at scale, they had an issue: if they switched to GUIDs, clients would break, because they were sorting based on the ID value. They had to invent an entirely new algorithm (Snowflake) to adapt to this change. This wouldn't have happened if they hadn't leaked internal details. It's basic encapsulation.
- MichaelGG 14y agoI'm not sure how the Twitter example is remotely related to what I'm asking. You're saying that if Twitter returned long URLs as opaque tokens to get, then it'd have been ok. Sure, but it'd have been fine if they had made the tweet id an opaque token either way. Surely returning named URL pairs isn't "basic encapsulation", and "GET /Tweet/<token>" has no reason to break. I can see how returning hypermedia adds yet another layer of abstraction (and potentially plenty more round trips!). I'm just unsure how it helps. I don't understand how actual client code (besides a browser) can deal with arbitrary hypermedia. I'm cautious when I don't understand why people are hyped up about something, but I've yet to see any "real life" examples that demonstrate real benefits of this approach.
- IanCal 14y agoI can't point to them because they're internal, but there are some good ones I've used. Pagination was one useful part, where we saw the API change but didn't have to change the client. A second was being able to explore parent relationships, so we could start somewhere in the tree and move up until we hit the level we were interested in. There are always agreements between the API designers and client designers, because the code isn't intelligent, so it doesn't know what 'parent' means. If the name of that changes, then the client would have to change. What can be different is the url structure to get the 'parent'. Maybe there's a new token that has to be there, or the naming of something has been changed, or whatever. Those changes can be made without breaking the clients. Putting this in the responses means two things: 1) Small changes don't break everything (pagination is a great one, its a /pages/1 one day then ?page=1, then ?offset=25, then ?pageSize is optional, then it's required, etc.). 2) Fewer assumptions baked into the client. Getting the tweets for a user you've loaded would be nicer as load(user.tweets) than load("/tweets/"+user.id)
- barkmadley 14y agoThere is no such thing as "arbitrary hypermedia". watch these two very good talks on this topic: * http://oredev.org/2012/sessions/designing-hypermedia-apis http://oredev.org/2012/sessions/designing-hypermedia-apis * http://vimeo.com/20781278 http://vimeo.com/20781278
- heme 14y agoWSDL for REST is happening, but see the JSON schema discussion below. WADL is a machine-readable XML description of HTTP-based web applications (typically REST web services). http://en.wikipedia.org/wiki/Web_Application_Description_Language http://en.wikipedia.org/wiki/Web_Application_Description_Lan...