Expressify provides a few basic model classes that should help you construct resources in your microservices. They are built to work best with expressify’s HAL middleware and serializer library.

Resource is the most generic model class. A Resource can be anything and to use the HAL middleware, you should extend Resource.

Kind: global class

new Resource(data)

Resource constructor

Returns: Resource - the constructed resource

Param Type Description
data Object The resource’s properties

resource.assign(data) ⇒ this

Assign new data to the resource, behaves like Object.assign

Kind: instance method of Resource

Param Type Description
data Object The resource’s properties

resource.addEmbedded(name, data, [options]) ⇒ this

Add new embedded resources

Kind: instance method of Resource

Param Type Default Description
name string   Name for the set of embedded data
data Array   Array of Resource instances to embed
[options] Object   Array of Resource instances to embed
[options.concat] boolean true When true, concats array with existing embedded items, defaults to true

resource.getEmbedded(name) ⇒ Array | null

Return embedded items for name

Kind: instance method of Resource
Returns: Array | null - Embedded items or null

Param Type Description
name string The name of the embedded you want

resource.setType(type) ⇒ this

Set the type of resource

Kind: instance method of Resource

Param Type Description
type string The type to set

resource.getType() ⇒ string

Get the type of resource. Defaults to “Resource” if not set.

Kind: instance method of Resource
Returns: string - Type

resource.isTranslatable() ⇒ boolean

Check if the resource can be translated

Kind: instance method of Resource

resource.getLanguages() ⇒ Array

Get enabled languages of this resource.

Kind: instance method of Resource

resource.setLanguageKey(languageKey) ⇒ this

Set the key which is used to retrieve the enabled languages of this resource. Defaults to “languages” if not customized.

Kind: instance method of Resource

Param Type Description
languageKey string The key for the property that contains an array of the resource’s languages

Resource.factory(data) ⇒ Resource

Static method to create a new resource using the constructor

Kind: static method of Resource
Returns: Resource - the constructed resource

Param Type Description
data Object The resource’s properties