Hohenheim
A validator for JSONAPI responses.
Requirements
Hohenheim is written in ES6, so it requires a Node.js build (or browser) that
supports these features, or just io.js:
let
, const
- Template strings
for (... of ...)
Install
$ npm install --save-dev hohenheim
Usage
const Hohenheim = require('hohenheim');
Hohenheim.check(responseString).catch(...);
Hohenheim.check(responseJson).catch(...);
Hohenheim.check(res).catch(...); # Express response
Hohemhein.check(someJson, function(err, document) {
if (err) {
...
}
...
});
Checks
- That a response is either data or errors
- If it's data:
- that it has a
data
object or array, - and optionally
included
, links
, meta
arrays/objects, - but nothing more.
- That the layout of all objects is as specced
- That the included documents are referred to in the primary data
- That URIs (for links etc) are well-formed and as specced
- If given an object, that it is "plain" and contains no JSON-invalid data
- If given a string, that it is either:
- entirely valid JSON, or
a well-formed HTTP response containing a JSONAPI response. (TODO)
If given an HTTP response (either through a string or an Express res
):
that its Content-Type is application/vnd.api+json
,that its status is as specced,that it passes all the above.
Doesn't check (yet?)
- That URIs point to where/what they should
- Application-specific fields
- Pagination
- Sparse fieldsets
- Sorting
- Filtering
- Requests (sent by clients to create, update, delete resources)
Etc
Written by Félix Saparelli,
at McKay Software.
Released under the MIT License.
Named after a fictional alchemist.