1 | Ketting 🔗 - A hypermedia client for javascript
|
2 | ============================================
|
3 |
|
4 | * Go to the [Wiki][9] for full documentation.
|
5 |
|
6 | Introduction
|
7 | ------------
|
8 |
|
9 | The Ketting library is a generic REST client with Hypermedia features.
|
10 |
|
11 | The library will work with any JSON-based HTTP API, but it gets superpowers
|
12 | when 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 |
|
19 | And it even works with HTML links, and [HTTP Link Headers][1].
|
20 |
|
21 | Ketting is designed to both work in the browser and in Node.js. Additionally,
|
22 | it has [react bindings][ketting-react] that will make it work in a way that's
|
23 | familiar to Apollo-Client users.
|
24 |
|
25 | ### Example
|
26 |
|
27 | ```typescript
|
28 | const 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:`.
|
32 | const author = await ketting.follow('author');
|
33 |
|
34 | // Grab the current state
|
35 | const authorState = await author.get();
|
36 |
|
37 | // Change the firstName property of the object. Note that this assumes JSON.
|
38 | authorState.data.firstName = 'Evert';
|
39 |
|
40 | // Save the new state
|
41 | await author.put(authorState);
|
42 | ```
|
43 |
|
44 | Docs
|
45 | ----
|
46 |
|
47 | * [Installation][7]
|
48 | * [Full documentation][9]
|
49 | * [Authentication][2]
|
50 |
|
51 |
|
52 | Notable Features
|
53 | ----------------
|
54 |
|
55 | Ketting is a library that sits on top of [Fetch API][3] to provide a RESTful
|
56 | interface and make it easier to follow REST best practices more strictly.
|
57 |
|
58 | It provides some useful abstractions that make it easier to work with true
|
59 | hypermedia / HATEOAS servers. It currently parses many hypermedia formats
|
60 | and has a deep understanding of links and embedded resources. There's also
|
61 | support for parsing and following links from HTML documents, and it
|
62 | understands the HTTP `Link:` header.
|
63 |
|
64 | It also has support for 'fetch middlewares', which is used to implement
|
65 | OAuth2 support, but also opens the door to development of other plugins.
|
66 |
|
67 | Using this library it becomes very easy to follow links from a single bookmark,
|
68 | and discover resources and features on the server.
|
69 |
|
70 | Supported 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 |
|
82 | Other features:
|
83 |
|
84 | * [Prefer-Push][prefer-push]
|
85 | * [Prefer-Transclude][prefer-transclude]
|
86 | * It can submit HTML forms and Siren actions.
|
87 |
|
88 | Read 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
|