hal-ts
v1.0.12
Published
Package to format api responses into hal format
Downloads
23
Maintainers
Readme
Hal-Ts
package to create API data responses in Hal format
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js.
If this is a brand new project, make sure to create a package.json
first with
the npm init
command.
Installation is done using the
npm install
command:
$ npm install hal-ts
Examples
Data Object
import halts from "hal-ts";
const halResponse = generateObjectResponse({
url: "http://localhost:8080/api/users",
data: {
identifier: 1,
name: "Marcus",
isAlive: true,
_embeded: undefined,
},
})
import halts from "hal-ts";
const halResponse = generateObjectResponse({
url: "http://localhost:8080/api/users",
data: {
identifier: 1,
name: "Marcus",
isAlive: true,
_embeded: [{
identifier: 2,
name: "Mark",
isAlive: false,
_embeded: undefined,
}],
},
})
import halts from "hal-ts";
const halResponse = generateObjectResponse({
url: "http://localhost:8080/api/users",
data: {
identifier: 1,
name: "Marcus",
isAlive: true,
_embeded: {
identifier: 10,
name: "Klei",
url: "http://localhost:8080/api/pets",
_embeded: undefined,
},
},
})
Collections
import halts from "hal-ts";
const arrayData = [{
url: "http://localhost:8080/api/users",
data: {
identifier: 1,
name: "Marcus",
isAlive: true,
_embeded: undefined,
}
},
{
url: "http://localhost:8080/api/users",
data: {
identifier: 2,
name: "Markus",
isAlive: false,
_embeded: undefined,
},
} {
url: "http://localhost:8080/api/users",
data: {
identifier: 3,
name: "Marly",
isAlive: false,
_embeded: undefined,
},
},
{
url: "http://localhost:8080/api/users",
data: {
identifier: 4,
name: "Kane",
isAlive: true,
_embeded: undefined,
},
}
];
const baseData = {
data: arrayData;
chunk: 2;
page: 2;
url: "http://localhost/api/users";
collectionName: "users";
}
const halResponse = getCollectionResponse(baseData);