HAL

HAL

Represents a HAL ressource and simplifies its manipulation.

Constructor

new HAL(URL, contentopt)

Constructs.

Parameters:
Name Type Attributes Default Description
URL String | Url

of HAL resource

content Object <optional>
{}

default content of resource

Source:

Methods

_change(method, headersopt) → {Promise}

Core of POST and PUT operations to create/update the resource

Parameters:
Name Type Attributes Description
method String

either PUT, PATCH or POST

headers Object <optional>

optional request headers

Source:
Returns:

promise resolved with an containing body and the actual response

Type
Promise

_fetchEmbeddeds(depthopt) → {Promise}

Fetches the links and them as embedded resources.

Parameters:
Name Type Attributes Default Description
depth Number <optional>
-1

recursion depth

Source:
Returns:

promise resolved when all links are fetched

Type
Promise

_request(method, headers) → {Promise}

A simple wrapper around 'http.request' that returns a Promise. The host name is set by default to 'localhost'.

Parameters:
Name Type Description
method String

desired HTTP method (defaults to 'GET')

headers Object

desired headers

Source:
Returns:

promise resolved with an containing body and the actual response

Type
Promise

associate(resourceName, resourceUrl) → {Promise}

Associates this resource with given resource URL as given resource name.

NOTE: this method works properly with Spring data REST backends and might not work properly with other backends.

Parameters:
Name Type Description
resourceName String

desired resource name to associate

resourceUrl String

localtion of resource to be associated

Source:
Returns:

promise resolved with instance of this resource

Type
Promise

auth(credentials) → {HAL}

Parameters:
Name Type Description
credentials String

in basic auth 'USER:PASS' format

Source:
Returns:

instance

Type
HAL

body(body) → {HAL}

Parameters:
Name Type Description
body Object

instance body

Source:
Returns:

instance

Type
HAL

DELETE(headersopt) → {Promise}

Deletes the resource

Parameters:
Name Type Attributes Description
headers Object <optional>

optional headers

Source:
Returns:

promise resolving to this instance if succeeds

Type
Promise

embedded(key) → {Object}

Deep value retrieval from embedded items.

The key is in dot notation, e.g. 'statuses.2.numericValue' would look under embedded sensors, the second item, and finally its numericValue field.

NOTE: if at any part of the chain, the given key is not found, the result would explicitly be 'null' and no errors are thrown.

Parameters:
Name Type Description
key String

of embedded item (in dot notation)

Source:
Returns:

embedded item

Type
Object

follow(link, depthopt) → {Promise}

Follows a link by name

Parameters:
Name Type Attributes Default Description
link String

desired link

depth int <optional>
0

embedded recursion link (as in #GET)

Source:
Returns:

promise resolved with instance of fetched link

Type
Promise

GET(depthopt) → {HAL}

Fetches a HAL resource and embeds its links recursively. NOTE: to avoid circular references it is not recommended to have a value higher than 0 for depth!

Parameters:
Name Type Attributes Default Description
depth Number <optional>
0

denotes levels of recursion (-1 for none)

Source:
Returns:

self instance with its content field filled

Type
HAL
Parameters:
Name Type Description
key String

desired link name

Source:
Returns:

link's value

Type
Object

PATCH(headersopt) → {Promise}

Patches the ressource

Parameters:
Name Type Attributes Description
headers Object <optional>

optional headers

Source:
Returns:

promise resolves to this instance if succeeds

Type
Promise

POST(headersopt) → {Promise}

Creates a new ressource from this instance

Parameters:
Name Type Attributes Description
headers Object <optional>

optional headers

Source:
Returns:

promise resolves to this instance if succeeds

Type
Promise

PUT(headersopt) → {Promise}

Updates the ressource

Parameters:
Name Type Attributes Description
headers Object <optional>

optional headers

Source:
Returns:

promise resolves to this instance if succeeds

Type
Promise