LoopBack REST Builder

LoopBack REST Connector

exports.initialize(dataSource, [callback])

Export the initialize method to loopback-datasource-juggler

Arguments
Name Type Description
dataSource DataSource

The loopback data source instance

[callback] function

The callback function

RestConnector(baseURL)

The RestConnector constructor

Arguments
Name Type Description
baseURL string

The base URL

restConnector.define(definition)

Hook for defining a model by the data source

Arguments
Name Type Description
definition object

The model description

restConnector.installPostProcessor(definition)

Install the post processor

Arguments
Name Type Description
definition object

The model description

restConnector.preProcess(data)

Pre-process the request data

Arguments
Name Type Description
data

The request data

Returns
Name Type Description
result [object Object]

restConnector.postProcess(model, data, many)

Post-process the response data

Arguments
Name Type Description
model string

The model name

data

The response data

many boolean

Is it an array

restConnector.getResource(model)

Get a REST resource client for the given model

Arguments
Name Type Description
model string

The model name

Returns
Name Type Description
result

restConnector.create(model, data, [callback])

Create an instance of the model with the given data

Arguments
Name Type Description
model string

The model name

data object

The model instance data

[callback] function

The callback function

restConnector.updateOrCreate(model, data, [callback])

Update or create an instance of the model

Arguments
Name Type Description
model string

The model name

data object

The model instance data

[callback] function

The callback function

restConnector.responseHandler(model, [callback])

A factory to build callback function for a response

Arguments
Name Type Description
model string

The model name

[callback] function

The callback function

Returns
Name Type Description
result function

restConnector.save(model, data, [callback])

Save an instance of a given model

Arguments
Name Type Description
model string

The model name

data object

The model instance data

[callback] function

The callback function

restConnector.exists(model, id, [callback])

Check the existence of a given model/id

Arguments
Name Type Description
model string

The model name

id

The id value

[callback] function

The callback function

restConnector.find(model, id, [callback])

Find an instance of a given model/id

Arguments
Name Type Description
model string

The model name

id

The id value

[callback] function

The callback function

restConnector.destroy(model, id, [callback])

Delete an instance for a given model/id

Arguments
Name Type Description
model string

The model name

id

The id value

[callback] function

The callback function

restConnector.all(model, filter, [callback])

Query all instances for a given model based on the filter

Arguments
Name Type Description
model string

The model name

filter object

The filter object

[callback] function

The callback function

restConnector.destroyAll(model, [callback])

Delete all instances for a given model

Arguments
Name Type Description
model string

The model name

[callback] function

The callback function

restConnector.count(model, [callback], where)

Count cannot not be supported efficiently.

Arguments
Name Type Description
model string

The model name

[callback] function

The callback function

where object

The where object

restConnector.updateAttributes(model, id, data, [callback])

Update attributes for a given model/id

Arguments
Name Type Description
model string

The model name

id

The id value

data object

The model instance data

[callback] function

The callback function

LoopBack REST Model API

RestResource(modelCtor, baseUrl)

Build a REST resource client for CRUD operations

Arguments
Name Type Description
modelCtor function

The model constructor

baseUrl string

The base URL

Returns
Name Type Description
result RestResource

wrap(cb)

Wrap the callback so that it takes (err, result, response)

Arguments
Name Type Description
cb function

The callback function

Returns
Name Type Description
result

restResource.create(obj, [cb])

Map the create operation to HTTP POST /{model}

Arguments
Name Type Description
obj object

The HTTP body

[cb] function

The callback function

restResource.update(id, obj, [cb])

Map the update operation to POST /{model}/{id}

Arguments
Name Type Description
id

The id value

obj object

The HTTP body

[cb] function

The callback function

restResource.delete(id, [cb])

Map the delete operation to POST /{model}/{id}

Arguments
Name Type Description
id

The id value

[cb] function

The callback function

restResource.deleteAll(id, [cb])

Map the delete operation to POST /{model}

Arguments
Name Type Description
id

The id value

[cb] function

The callback function

restResource.find(id, [cb])

Map the find operation to GET /{model}/{id}

Arguments
Name Type Description
id

The id value

[cb] function

The callback function

restResource.all(q, [cb])

Map the all/query operation to GET /{model}

Arguments
Name Type Description
q object

query string

[cb] function

callback with (err, results)