UNPKG

3.67 kBMarkdownView Raw
1Ketting 🔗 - A hypermedia client for javascript
2============================================
3
4* Go to the [Wiki][9] for full documentation.
5
6Introduction
7------------
8
9The Ketting library is a generic REST client with Hypermedia features.
10
11The library will work with any JSON-based HTTP API, but it gets superpowers
12when using it with formats that have support for links, including:
13
14* [HAL][hal]
15* [JSON:API][jsonapi]
16* [Siren][siren],
17* [Collection+JSON][coljson]
18
19And it even works with HTML links, and [HTTP Link Headers][1].
20
21Ketting is designed to both work in the browser and in Node.js. Additionally,
22it has [react bindings][ketting-react] that will make it work in a way that's
23familiar to Apollo-Client users.
24
25### Example
26
27```typescript
28const ketting = new Ketting('https://api.example.org/');
29
30// Follow a link with rel="author". This could be a HTML5 `<link>`, a
31// HAL `_links` or a HTTP `Link:`.
32const author = await ketting.follow('author');
33
34// Grab the current state
35const authorState = await author.get();
36
37// Change the firstName property of the object. Note that this assumes JSON.
38authorState.data.firstName = 'Evert';
39
40// Save the new state
41await author.put(authorState);
42```
43
44Docs
45----
46
47* [Installation][7]
48* [Full documentation][9]
49* [Authentication][2]
50
51
52Notable Features
53----------------
54
55Ketting is a library that sits on top of [Fetch API][3] to provide a RESTful
56interface and make it easier to follow REST best practices more strictly.
57
58It provides some useful abstractions that make it easier to work with true
59hypermedia / HATEOAS servers. It currently parses many hypermedia formats
60and has a deep understanding of links and embedded resources. There's also
61support for parsing and following links from HTML documents, and it
62understands the HTTP `Link:` header.
63
64It also has support for 'fetch middlewares', which is used to implement
65OAuth2 support, but also opens the door to development of other plugins.
66
67Using this library it becomes very easy to follow links from a single bookmark,
68and discover resources and features on the server.
69
70Supported formats:
71
72* [HAL][hal]
73* [Siren][siren] - Including support for actions.
74* HTML - Can automatically follow `<link>` and `<a>` element with `rel=`
75 attributes, and submit HTML `<form>`s.
76* [HTTP Link header][1] - automatically registers as links regardless of format.
77* [JSON:API][jsonapi] - Understands the `links` object and registers collection
78 members as `item` relationships.
79* [application/problem+json][problem] - Will extract useful information from
80 the standard problem object and embed them in exception objects.
81
82Other features:
83
84* [Prefer-Push][prefer-push]
85* [Prefer-Transclude][prefer-transclude]
86* It can submit HTML forms and Siren actions.
87
88Read further on the [Wiki][9]
89
90
91[1]: https://tools.ietf.org/html/rfc8288 "Web Linking"
92[2]: https://github.com/evert/ketting/wiki/Authentication
93[3]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
94
95[7]: https://github.com/evert/ketting/wiki/Installation
96[8]: https://github.com/evert/ketting/wiki/Getting-Started
97[9]: https://github.com/evert/ketting/wiki/
98
99[hal]: http://stateless.co/hal_specification.html "HAL - Hypertext Application Language"
100[jsonapi]: https://jsonapi.org/
101[problem]: https://tools.ietf.org/html/rfc7807
102[siren]: https://github.com/kevinswiber/siren "Structured Interface for Representing Entities"
103[coljson]: http://amundsen.com/media-types/collection/format/
104[prefer-push]: https://tools.ietf.org/html/draft-pot-prefer-push
105[prefer-transclude]: https://github.com/inadarei/draft-prefer-transclude/blob/master/draft.md
106[react-ketting]: https://github.com/badgateway/react-ketting