The are lots of ways to walk the API: the todo app displays it with a user interface; the general api browser walks and allows simple updates. Cloning resources extends the general purpose client and programmatically makes it possible to deal with complicated updates—its purpose is to make copies in bulk without people intervention. One easy example is the business problem of moving data between environments (eg between test to another test environment, or bringing production data back into another environment or from a production staging/testing into production).
All of this is made possible because hypermedia uses forms to instruct the client.
All of this done using the semantic network library and the purpose of this tutorial is show how it is used (not how to build it) and the mental model it requires.
Note: the drag’n’drop is just user-sugar to make the interaction practical. Again, if you want to understand the mechanics drag’n’drop look at the code (but the issue is that HTML5 API here is the right thing to do).
Both processes require first a copy to made.
The semantic-network
library provides get
(as well as create
, update
and delete
) to help build up a cache of network of data based on link relations. Study the implementation below to see that primarily all the developer needs to know is the link relation and can optionally add strategies for eager and lazy loading, for instance. In this implementation, the knowledge of the link relations is kept out of the framework specific code (hence in the domain
folder) for the usual reasons of reuse, testing and intention. Also, note that types are explicitly defined and are used in parameters and return types.
The semantic-network
library provides sync
to walk the network of data based on link relations loading up representations and their forms and then working out whether to update, create or delete based on the presented representation/document. Study the implementation below to see that:
rel: /todos/
) the strategies
provides a recursive structure for depth and width control. ...syncResult
) that passes through necessary parameters{resource, document, options})
where you want to include options What is the difference between the two in the context of hypermedia? How to know whether to call create or update? You don’t. The question the code asks of the data is the difference in state. Do you exist? Are you different?
In the sample, you can force a create by changing the root resource identity. This requires two changes, remove the ‘self’ link and change the ‘name’ attribute.