Skip to content
A tool (also website) validating a Hydra API against possible mistakes
Branch: master
Clone or download
dependabot-preview and tpluscode [Security] Bump lodash.template from 4.4.0 to 4.5.0
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0. **This update includes security fixes.**
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.4.0...4.5.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Latest commit 016e05b Jul 11, 2019

README.md

hydra-validator

A tool (also website) validating a Hydra API against possible mistakes

Usage

Online tool

To check any endpoint for Hydra controls and their correctness go to https://analyse.hypermedia.app and paste an URL to the textbox and press ENTER.

The website will dereference that resource and linked API Documentation (if any) and try to check it against the implemented rules.

For the online version to work, the API must be served over HTTPS and CORS must be enabled on the server.

Command Line tool

It is also possible to run verification of a Hydra API fomr the command line. This may be useful to run sanity checks locally during development or as part of a CI pipeline.

To install

npm i -g hydra-validator

And then run

hydra-validator analyze <URL>

Contributing

Each verification check is a parameterless function, which returns the result and optionally an array of child checks. It can also be async.

export interface CheckResult {
    result?: IResult;
    results?: IResult[];
    nextChecks?: checkChain[];
    sameLevel?: boolean;
}

export type checkChain = (this: Context) => Promise<CheckResult> | CheckResult

To implement a check, you'd usually wrap the check function in a closure to pass in dependencies. This way checks are chained to run when the previous check succeeds.

Here's an example which could verify that the input is a number and then pass on to a check for parity.

// isnum.ts
import {checkChain, Result} from '../check';
import iseven from './iseven';

export default function (maybeNum: any): checkChain {
    return () => {
        if (Number.isInteger(maybeNum)) {
            return {
                result: Result.Success('Value is number'),
                nextChecks: [ iseven(maybeNum) ]
            }
        }

        return {
            result: Result.Failure('Value is not a number')
        }
    }
}

// iseven.ts
import {checkChain, Result} from '../check';

export default function (num: number): checkChain {
    return () => {
        const result = num % 2 === 0
            ? Result.Success(`Number ${num} is even`)
            : Result.Failure(`Number ${num} is odd`)

        return { result }
    }
}

Any new check must be added to existing chains in a similar matter to how iseven follows isnum.

Results can be reported with four factory methods: Result.Succes, Result.Failure, Result.Warning and Result.Informational.

Note that there is no restriction for chaining. Additional checks can follow a successful check as well as failed ones.

You can’t perform that action at this time.