Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hohenheim

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hohenheim

JSONAPI validator

  • 0.0.1
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

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');

// By default, returns a Promise:
Hohenheim.check(responseString).catch(...);
Hohenheim.check(responseJson).catch(...);
Hohenheim.check(res).catch(...); # Express response

// But you can choose to have Booleans, Exceptions, or Nodebacks:
{
  const Hohenheim = require('hohenheim/bool');
  let isValid = Hohenheim.check(aResponse);
}

{
  const Hohenheim = require('hohenheim/throw');
  try {
    Hohenheim.check(aString);
  } catch(e) {
    if (e instanceof Hohenheim.Error) {
      ...
    } else {
      throw e;
    }
  }
}

{
  const Hohenheim = require('hohenheim/callback');
  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.
  • 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.

Keywords

FAQs

Package last updated on 24 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc