ketting
v7.5.2
Published
Opiniated HATEAOS / Rest client.
Downloads
4,881
Maintainers
Readme
Ketting - The HATEOAS client for javascript
Check out the Wiki for full documentation.
Introduction
The Ketting library is a generic REST client with Hypermedia features.
The library will work with any JSON-based HTTP API, but it gets superpowers when using it with formats that have support for links, including:
- HAL + HAL Forms
- JSON:API
- Siren,
- Collection+JSON
- application/problem+json - Will extract useful information from the standard problem object and embed them in exception objects.
And it even works with HTML links, and HTTP Link Headers.
Ketting is designed to both work in the browser and in Node.js. Additionally, it has react bindings that will make it work in a way that's familiar to Apollo-Client users.
Example
const ketting = new Ketting('https://api.example.org/');
// Follow a link with rel="author". This could be a HTML5 `<link>`, a
// HAL `_links` or a HTTP `Link:`.
const author = await ketting.follow('author');
// Grab the current state
const authorState = await author.get();
// Change the firstName property of the object. Note that this assumes JSON.
authorState.data.firstName = 'Evert';
// Save the new state
await author.put(authorState);
Docs
Notable Features
Ketting is a library that sits on top of Fetch API to provide a RESTful interface and make it easier to follow REST best practices more strictly.
It provides some useful abstractions that make it easier to work with true
hypermedia / HATEOAS servers. It currently parses many hypermedia formats
and has a deep understanding of links and embedded resources. There's also
support for parsing and following links from HTML documents, and it
understands the HTTP Link:
header.
It also has support for 'fetch middlewares', which is used to implement OAuth2 support, but also opens the door to development of other plugins.
Using this library it becomes very easy to follow links from a single bookmark, and discover resources and features on the server.
Read further on the Wiki