Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inadarei/kokua
Hypermedia Representor implemented with Hyper+json
https://github.com/inadarei/kokua
collection-json hal hyper hypermedia siren uber
Last synced: 3 months ago
JSON representation
Hypermedia Representor implemented with Hyper+json
- Host: GitHub
- URL: https://github.com/inadarei/kokua
- Owner: inadarei
- License: mit
- Created: 2017-12-24T01:18:10.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2022-08-25T18:49:31.000Z (over 2 years ago)
- Last Synced: 2024-08-11T10:48:57.296Z (5 months ago)
- Topics: collection-json, hal, hyper, hypermedia, siren, uber
- Language: JavaScript
- Homepage: http://hyperjson.io/
- Size: 84 KB
- Stars: 4
- Watchers: 7
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README-PLUGINDEV.md
- License: LICENSE
Awesome Lists containing this project
README
# Kōkua - Plugin Developer's Guide
Typical structure of a plugin looks like the following:
```javascript
const log = require("metalogger")();
const _ = require("lodash");
const traverse = require("traverse");
const hutil = require("./hutil");class YourNewPlugin {
constructor(message) {
if (typeof message !== 'object') {
this.doc = JSON.parse(message);
} else {
this.doc = message;
}
this.newDoc = {};
}translate() {
this.handleSomeTransformation();
this.hanldeAnotherTransformation();
this.hanldeYetAnotherTransformation();return this.newDoc;
}
}module.exports = (doc) => {
const representor = new YourNewPlugin(doc);
return representor;
};
```To add a new implementation to Kokua, a corresponding setting should be
added to the list of supported plugins in lib/kokua.js:```javascript
const formats = {
"hal" : "application/hal+json",
"siren" : "application/vnd.siren+json",
"coljson" : "application/vnd.collection+json",
"uber" : "application/vnd.uber+json","shortname" : "official/media+type"
};
```### Plugin Implementation File Naming
If you are implementing Hyper -> HAL conversion, and the entry in the formats
array is `"hal" : "application/hal+json"` then:1. lib/plugins/hal.js - implements conversion from Hyper to HAL
1. lib/plugins/hal-reverse.js - implements conversion from HAL to HyperIn either case the structure of the file is as shown above.
### Tests!
Last but not least: obviously a plugin should be fully covered with tests.