Load the REST request from a JSON object
Name | Type | Description |
---|---|---|
req |
object
|
The request json object |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
Name | Type | Description |
---|---|---|
[method] |
string
|
HTTP method |
url |
string or object
|
The HTTP URL or an object for the options including method, url properties |
[requestFunc] |
function
|
Custom request with defaults |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
Attach a model to the REST connector
Name | Type | Description |
---|---|---|
modelCtor |
function
|
The model constructor |
baseUrl |
string
|
The base URL |
Name | Type | Description |
---|---|---|
result |
RestResource
|
Delegation to request Please note the cb takes (err, body, response)
Name | Type | Description |
---|---|---|
uri |
string
|
The HTTP URI |
options |
options
|
The options |
cb |
function
|
The callback function |
Queue the given file
as an attachment
with optional filename
.
Name | Type | Description |
---|---|---|
field |
string
|
|
file |
string
|
|
filename |
string
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Set Authorization field value with user
and pass
.
Name | Type | Description |
---|---|---|
user |
string
|
The user name |
pass |
string
|
The password |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Send body
, defaulting the .type()
to "json" when
an object is given.
Examples:
// manual json
request.post('/user')
.type('json')
.body('{"name":"tj"}');
// auto json
request.post('/user')
.body({ name: 'tj' });
// manual x-www-form-urlencoded
request.post('/user')
.type('form')
.body('name=tj');
// auto x-www-form-urlencoded
request.post('/user')
.type('form')
.body({ name: 'tj' });
// string defaults to x-www-form-urlencoded
request.post('/user')
.body('name=tj')
.body('foo=bar')
.body('bar=baz');
Name | Type | Description |
---|---|---|
body |
string or object
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Enable / disable buffering.
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Build the request by expanding the templatized properties with the named values from options
Name | Type | Description |
---|---|---|
options |
object
|
Name | Type | Description |
---|---|---|
result |
|
Set header field
to val
, or multiple fields with one object.
Examples:
req.get('/')
.header('Accept', 'application/json')
.header('X-API-Key', 'foobar');
req.get('/')
.header({ Accept: 'application/json', 'X-API-Key': 'foobar' });
Name | Type | Description |
---|---|---|
field |
string or object
|
|
val |
string
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Invoke a REST API with the provided parameter values in the parameters object
Name | Type | Description |
---|---|---|
parameters |
object
|
An object that provide {name: value} for parameters |
cb |
function
|
The callback function |
Configure the HTTP method
Name | Type | Description |
---|---|---|
method |
string
|
The HTTP method |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
Map the request builder to a function
Name | Type | Description |
---|---|---|
parameterNames |
String or Array.<String>
|
The parameter names that define the order of args. It be an array of strings or multiple string arguments |
Name | Type | Description |
---|---|---|
result |
Function
|
A function to invoke the REST operation |
Define the parser to be used for this response.
Name | Type | Description |
---|---|---|
fn |
function
|
The parser function |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Add query-string val
.
Examples:
request.get('/shoes') .query('size=10') .query({ color: 'blue' })
Name | Type | Description |
---|---|---|
val |
object or string
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Set the max redirects to n
.
Name | Type | Description |
---|---|---|
n |
number
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Set the response json path
Name | Type | Description |
---|---|---|
responsePath |
string
|
The JSONPath to be applied against the HTTP body |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
Set timeout to ms
.
Name | Type | Description |
---|---|---|
ms |
Number
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Serialize the RequestBuilder to a JSON object
Name | Type | Description |
---|---|---|
result |
[object Object]
|
Set Content-Type response header passed through mime.getType()
.
Examples:
request.post('/')
.type('xml')
.body(xmlstring);
request.post('/')
.type('json')
.body(jsonstring);
request.post('/')
.type('application/json')
.body(jsonstring);
Name | Type | Description |
---|---|---|
type |
string
|
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
for chaining |
Configure the url
Name | Type | Description |
---|---|---|
url |
string
|
The HTTP URL |
Name | Type | Description |
---|---|---|
result |
RequestBuilder
|
Name | Type | Description |
---|---|---|
dataSource |
DataSource
|
The loopback data source instance |
[callback] |
function
|
The callback function |
Name | Type | Description |
---|---|---|
baseURL |
string
|
The base URL |
settings |
object
|
The settings |
Query all instances for a given model based on the filter
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
filter |
object
|
The filter object |
[callback] |
function
|
The callback function |
Count cannot not be supported efficiently.
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
[callback] |
function
|
The callback function |
where |
object
|
The where object |
Create an instance of the model with the given data
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
data |
object
|
The model instance data |
[callback] |
function
|
The callback function |
Hook for defining a model by the data source
Name | Type | Description |
---|---|---|
definition |
object
|
The model description |
Delete an instance for a given model/id
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
id |
|
The id value |
[callback] |
function
|
The callback function |
Delete all instances for a given model
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
[callback] |
function
|
The callback function |
Check the existence of a given model/id
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
id |
|
The id value |
[callback] |
function
|
The callback function |
Find an instance of a given model/id
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
id |
|
The id value |
[callback] |
function
|
The callback function |
Get a REST resource client for the given model
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
Name | Type | Description |
---|---|---|
result |
|
Get types associated with the connector
Name | Type | Description |
---|---|---|
result |
Array.<String>
|
The types for the connector |
Install the post processor
Name | Type | Description |
---|---|---|
definition |
object
|
The model description |
Post-process the response data
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
data |
|
The response data |
many |
boolean
|
Is it an array |
Pre-process the request data
Name | Type | Description |
---|---|---|
data |
|
The request data |
Name | Type | Description |
---|---|---|
result |
[object Object]
|
A factory to build callback function for a response
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
[callback] |
function
|
The callback function |
Name | Type | Description |
---|---|---|
result |
function
|
Save an instance of a given model
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
data |
object
|
The model instance data |
[callback] |
function
|
The callback function |
Update attributes for a given model/id
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
id |
|
The id value |
data |
object
|
The model instance data |
[callback] |
function
|
The callback function |
Update or create an instance of the model
Name | Type | Description |
---|---|---|
model |
string
|
The model name |
data |
object
|
The model instance data |
[callback] |
function
|
The callback function |
Name | Type | Description |
---|---|---|
pluralModelName |
string
|
The model name |
baseUrl |
string
|
The base URL |
[requestFunc] |
function
|
Custom request with defaults |
Name | Type | Description |
---|---|---|
result |
RestResource
|
Map the all/query operation to GET /{model}
Name | Type | Description |
---|---|---|
q |
object
|
query string |
[cb] |
function
|
callback with (err, results) |
Map the create operation to HTTP POST /{model}
Name | Type | Description |
---|---|---|
obj |
object
|
The HTTP body |
[cb] |
function
|
The callback function |
Map the delete operation to POST /{model}/{id}
Name | Type | Description |
---|---|---|
id |
|
The id value |
[cb] |
function
|
The callback function |
Map the delete operation to POST /{model}
Name | Type | Description |
---|---|---|
id |
|
The id value |
[cb] |
function
|
The callback function |
Map the find operation to GET /{model}/{id}
Name | Type | Description |
---|---|---|
id |
|
The id value |
[cb] |
function
|
The callback function |
Map the update operation to POST /{model}/{id}
Name | Type | Description |
---|---|---|
id |
|
The id value |
obj |
object
|
The HTTP body |
[cb] |
function
|
The callback function |