Skip to content

HTTP

Call REST endpoints on the device.

See HTTP driver examples on GitHub.


Executes an HTTP DELETE request towards the device.

Signature

D.device.http.delete(options, callback)

Parameters

options · `object`
The HTTP request options
options.url · `string`
The url suffix of the request target
options.headers · `object` · optional
The Request HTTP Headers defined as key value pairs. Eg {'Accept': 'text/html'}
options.body · `string` · optional
The Request HTTP Body
options.port · `integer` · optional, default `80`
The port to use for the request. If protocol is set to https the default is 443
options.auth · `string` · optional
Set to 'basic' to attach HTTP Basic auth using the Custom Driver Management credentials (or options.username/options.password when provided). Any other value is ignored.
options.username · `string` · optional
The device username. If not set the custom driver management purpose one is used
options.password · `string` · optional
The device password. If not set the custom driver management purpose one is used
options.jar · `boolean` · optional
If true, remember cookies for future use
options.useHostname · `boolean` · optional, default `true`
If false, ip address is used as host. If true or not set the device host_name is used as host
options.protocol · `'http'` | `'https'` · optional, default `'http'`
The protocol to use in the request
callback · `function`
The HTTP request execution callback
callback.error · `Error` | `null`
The HTTP response error
callback.response · `Object` | `null`
The HTTP response object
callback.body · `string` | `null` · optional
The HTTP response body

Returns

  • void

Example

D.device.http.delete(options, callback)

Executes an HTTP GET request towards the device.

Signature

D.device.http.get(options, callback)

Parameters

options · `object`
The HTTP request options
options.url · `string`
The url suffix of the request target
options.headers · `object` · optional
The Request HTTP Headers defined as key value pairs. Eg {'Accept': 'text/html'}
options.body · `string` · optional
The Request HTTP Body
options.port · `integer` · optional, default `80`
The port to use for the request. If protocol is set to https the default is 443
options.auth · `string` · optional
Set to 'basic' to attach HTTP Basic auth using the Custom Driver Management credentials (or options.username/options.password when provided). Any other value is ignored.
options.username · `string` · optional
The device username. If not set the custom driver management purpose one is used
options.password · `string` · optional
The device password. If not set the custom driver management purpose one is used
options.jar · `boolean` · optional
If true, remember cookies for future use
options.useHostname · `boolean` · optional, default `true`
If false, ip address is used as host. If true or not set the device host_name is used as host
options.protocol · `'http'` | `'https'` · optional, default `'http'`
The protocol to use in the request
callback · `function`
The HTTP request execution callback
callback.error · `Error` · optional
The HTTP response error
callback.response · `Object` · optional
The HTTP response object
callback.body · `string` · optional
The HTTP response body

Returns

  • void

Example

D.device.http.get(options, callback)

Retrieves the TLS certificate of the server.

Signature

D.device.http.getTLSCertificate(options, callback)

Parameters

options · `object`
The getTLSCertificate options
options.port · `integer` · optional, default `443`
The port to use for the request. Default is 443
callback · `function`
The TLS info callback
callback.error · `ErrorResult` · optional
Will be present if the execution resulted in an error
callback.response · `Object`
The HTTP response object
callback.response.issuer · `string`
The issuer of the TLS certificate
callback.response.expiry · `string`
The expiry date of the TLS certificate
callback.response.valid · `Boolean`
True if the certificate is valid, false otherwise
callback.response.certError · `string`
An error code if the certificate is not valid, null otherwise

Returns

  • void

Example

D.device.http.getTLSCertificate(options, callback)
// callback returns (error, TLSData) where TLSData has the following format
{"issuer": "Issuer name", "expiry": "Apr 12 23:59:59 2015 GMT", "valid": false, "certError": "CERT_HAS_EXPIRED"}

Executes an HTTP POST request towards the device.

Signature

D.device.http.post(options, callback)

Parameters

options · `object`
The HTTP request options
options.url · `string`
The url suffix of the request target
options.headers · `object` · optional
The Request HTTP Headers defined as key value pairs. Eg {'Accept': 'text/html'}
options.body · `string` · optional
The Request HTTP Body
options.port · `integer` · optional, default `80`
The port to use for the request. If protocol is set to https the default is 443
options.auth · `string` · optional
Set to 'basic' to attach HTTP Basic auth using the Custom Driver Management credentials (or options.username/options.password when provided). Any other value is ignored.
options.username · `string` · optional
The device username. If not set the custom driver management purpose one is used
options.password · `string` · optional
The device password. If not set the custom driver management purpose one is used
options.jar · `boolean` · optional
If true, remember cookies for future use
options.useHostname · `boolean` · optional, default `true`
If false, ip address is used as host. If true or not set the device host_name is used as host
options.protocol · `'http'` | `'https'` · optional, default `'http'`
The protocol to use in the request
callback · `function`
The HTTP request execution callback
callback.error · `Error` | `null`
The HTTP response error
callback.response · `Object` | `null`
The HTTP response object
callback.body · `string` | `null` · optional
The HTTP response body

Returns

  • void

Example

D.device.http.post(options, callback)

Executes an HTTP PUT request towards the device.

Signature

D.device.http.put(options, callback)

Parameters

options · `object`
The HTTP request options
options.url · `string`
The url suffix of the request target
options.headers · `object` · optional
The Request HTTP Headers defined as key value pairs. Eg {'Accept': 'text/html'}
options.body · `string` · optional
The Request HTTP Body
options.port · `integer` · optional, default `80`
The port to use for the request. If protocol is set to https the default is 443
options.auth · `string` · optional
Set to 'basic' to attach HTTP Basic auth using the Custom Driver Management credentials (or options.username/options.password when provided). Any other value is ignored.
options.username · `string` · optional
The device username. If not set the custom driver management purpose one is used
options.password · `string` · optional
The device password. If not set the custom driver management purpose one is used
options.jar · `boolean` · optional
If true, remember cookies for future use
options.useHostname · `boolean` · optional, default `true`
If false, ip address is used as host. If true or not set the device host_name is used as host
options.protocol · `'http'` | `'https'` · optional, default `'http'`
The protocol to use in the request
callback · `function`
The HTTP request execution callback
callback.error · `Error` | `null`
The HTTP response error
callback.response · `Object` | `null`
The HTTP response object
callback.body · `string` | `null` · optional
The HTTP response body

Returns

  • void

Example

D.device.http.put(options, callback)