1.0.12 • Published 2 years ago

hal-ts v1.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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);
1.0.2

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago