Package Exports
- hateoasis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hateoasis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
HateOasis
An automatic HATEOAS traversing client.
Installation
Node.js
$ npm install hateoasisExample usage:
It's recommended creating interfaces extending the Hateoas interface for all api responses.
export default interface Client extends Hateoas {
public name: string;
public address: string;
etc...
}The Hateoas interface includes a links property of type Hateoaslinks. When constructing an Hateoas object it requires you to create the links.
Serverside example:
...
const client: Client = {
name: 'John Doe',
address: 'Whereville',
links: [
{
rel: 'self',
method: 'GET',
href: '/api/clients/1'
}
]
}
res.status(200).json(client);Too use HATEOAS from start, the server needs to have an index showing all available requests:
export default interface ApiIndex extends Hateoas {
version: string;
}const index: Hateoas = {
version: '1.0.0',
links: [
{
rel: 'clients',
method: 'GET',
href: '/api/clients'
}
]
}
res.status(200).json(index);Clientside example:
axios.get('/api').then(async response => {
const apiIndex = hateoasis(response.data);
const client = await apiIndex.request<Client>('client', 'GET');
console.log(client.data);
// If using strict TypeScript
const client = isRequestable(apiIndex) && await apiIndex.request<Client>('client', 'GET');
console.log(client.data);
});