(a) Hypermedia | (b) | (c) | (d) | (e) GraphQL |
A distributed hypermedia architect has only three fundamental options:
- render the data where it is located and send a fixed-format image to the recipient;
- encapsulate the data with a rendering engine and send both to the recipient; or,
- send the raw data to the recipient along with metadata that describes the data type, so that the recipient can choose their own rendering engine.
REST provides a hybrid of all three options by focusing on a shared understanding of data types with metadata, but limiting the scope of what is revealed to a standardized interface.
How do the server and client share understanding of data types?
Profiles, and registered media types.
Where do we get our standardized interface?
Our types, and our protocol.
But HTTP sux. :c
That's just one protocol. Don't let it box you in! (Also: no it doesn't.)
The model application is therefore an engine that moves from one state to the next by examining and choosing from among the alternative state transitions in the current set of representations.
How can we expose alternative state transitions in the current set of representations?
Hypermedia.
Hypermedia is defined by the presence of application control information embedded within, or as a layer above, the presentation of information. Distributed hypermedia allows the presentation and control information to be stored at remote locations.
When you have relatively little control over your clients, ie., can't expect them to update (mobile).
When you need properties like dynamic dispatch (associating an implementation with an operation) and dynamic binding (associating a name with an operation) in your program.
Hypermedia requires the client to work with a certain granularity of programmatically generatable interaction units.
This would make working with Storyboard driven development in iOS difficult and maybe impossible.
In Android, activities need to be declared in the manifest at compile time, but fragments could be generated during runtime.
Our new mental model: Graphs
Importantly, the client can request different sized "graphs" based on a set of tradeoffs like no network requests vs flexibility.
Want to minimize requests? Grab the biggest possible representation of application state with controls embedded of other potential application states, cache it, and move on.
Want to allow flexibility? Grab the smallest representation of application state with minimal controls linking (referencing, like reference types) to other potential application states.
* if the client supports meta-programming or polymorphic representation of untyped data (like maps) hypermedia can solve this problem. yes, static langs can be meta-programmed. no, i have not lost my mind. 😅
All of these correspond to adding new nodes or edges to our graph. Done right the "hypermedia way" these can be done without the client needing to ever release a change.
this means:
😑 idgi...
Check out my extended presentation on hypermedia, discuss in #rest
on freenode, or if all else fails, ask me. 😁