1.2.0 • Published 3 years ago

hateoas-link-resolver v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

HATEOAS-link-resolver

Build Status Maintainability Test Coverage

Small helper library for resolving templated HATEOAS links

Install

Use your favourite package manager

npm i -S hateoas-link-resolver

or

yarn add hateoas-link-resolver

Usage

Just resolve templated links

import { resolve } from 'hateoas-link-resolver';
const templatedLink = 'https://example.org/{id}/sub';
const resolvedLink = resolve(link, {id: '123'});

Use Link repository. Put all link into repository and then retrieve from there and resolve

import { LinkRepository } from 'hateoas-link-resolver';
const links = {
    endpoint1: {
        href: "https://example.org/{id}",
        templated: true
    },
    endpoint2: {
        href: "https://example.org/path/{id}",
        templated: true
    }
};
const repo = new LinkRepository(links);

// resolve
repo.resolve('endpoint1', {id: '123'});

// check existence
repo.has('endpoint1');

// get unresolved link
repo.get('endpoint1');

Limitations

This helper is for rather simple link structures and does not support list of links.

Alternatives

If you need resolving of list of links you might want to try hateoas-hal-link-resolver

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago