Skip to content

Instantly share code, notes, and snippets.

@ttahmouch
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save ttahmouch/91ec74aef00e0ef4295b to your computer and use it in GitHub Desktop.

Select an option

Save ttahmouch/91ec74aef00e0ef4295b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Coast Browser</title>
</head>
<body>
<script src="http://127.0.0.1:8080/ua"></script>
<script>
(function (window) {
window.onload = function () {
/**
* Note: There is only one URL hard-coded within the entire application.
* Links and forms are followed from responses.
*/
var client = hypermedia.Api.enter('http://127.0.0.1:8080/notes', function (error, res) {
console.log(res && res.status === 200 ? res.body : 'failed');
client.can('createNote').do({ body: { title: 'Something cool.' } }, function (error, res) {
console.log(res && res.status === 201 ? res.body : 'failed');
client.can('getNotes').do(function (error, res) {
console.log(res && res.status === 200 ? res.body : 'failed');
client.can('getNote').do({ uri: { id: '0' } }, function (error, res) {
console.log(res && res.status === 200 ? res.body : 'failed');
client.can('deleteNote').do({ uri: { id: '0' } }, function (error, res) {
console.log(res && res.status === 200 || res.status === 204);
client.can('getNotes').do(function (error, res) {
console.log(res && res.status === 200 ? res.body : 'failed');
client.can('deleteNote').do({ uri: { id: '0' } }, function (error, res) {
console.log(res && res.status === 200 || res.status === 204);
client.can('getNotes').do(function (error, res) {
console.log(res && res.status === 200 ? res.body : 'failed');
});
});
});
});
});
});
});
}, true);
};
})(window);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment