Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/footageone/hateoas-link-resolver
Small helper to resolve HATEOAS links
https://github.com/footageone/hateoas-link-resolver
hateoas hateoas-link-resolver rest rest-api rest-client
Last synced: about 1 month ago
JSON representation
Small helper to resolve HATEOAS links
- Host: GitHub
- URL: https://github.com/footageone/hateoas-link-resolver
- Owner: footageone
- License: mit
- Created: 2019-12-24T12:03:22.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-14T01:20:15.000Z (about 2 months ago)
- Last Synced: 2024-11-14T02:23:56.000Z (about 2 months ago)
- Topics: hateoas, hateoas-link-resolver, rest, rest-api, rest-client
- Language: TypeScript
- Homepage:
- Size: 746 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HATEOAS-link-resolver
![build](https://github.com/footageone/HATEOAS-link-resolver/actions/workflows/build.yml/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/ef5099936ee4de8a26d4/maintainability)](https://codeclimate.com/github/footageone/HATEOAS-link-resolver/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/ef5099936ee4de8a26d4/test_coverage)](https://codeclimate.com/github/footageone/HATEOAS-link-resolver/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
````javascript
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````javascript
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](https://github.com/just-paja/hateoas-hal-link-resolver)