Skip to content

Resource

Handles transformation of a single resource.

Constructor

ts
new Resource(resource, response?)

Parameters

ParameterTypeDescription
resourceResourceDataData to transform
responseExpress Response (optional)Auto-send support

Methods

data()

Returns the flattened resource.

ts
resource.data();

toArray()

Returns the transformed data without wrapping in { data }.

ts
resource.toArray();

additional(extra)

Merge additional properties into the response body.

ts
resource.additional({
  status: 'success',
  message: 'User created',
});

response()

Returns a ServerResponse instance.

ts
resource.response();

Promise Support

Resource is promise-like.

ts
await new Resource(user, res);

or

ts
new Resource(user, res).then((body) => {
  console.log(body);
});