Scandit.Http

Methods

(static) get(url: string, options?: object): Promise

Performs an HTTP GET request

Parameters:
Name Type Attributes Default Description
url string

Request url

options object <optional>
{}

Request options (same as Scandit.Http.request)

Properties
Name Type Attributes Description
body string <optional>

The body as a string, for example JSON

query object <optional>

Request query parameters (aka. query string)

headers object <optional>

Additional request headers. E.g. {authorization: 'Basic xxxxx'}

files object <optional>

Creates a multipart form upload POST request to send one or more files. E.g. {filename1: '/file/is/here.txt', filename2: '/another.png'}

formData object <optional>

Form body payload (will be sent together with files if provided)

timeout integer <optional>

Request timeout in seconds

connectionTimeout integer <optional>

Connection timeout in seconds

Returns:
Examples
  • JavaScript
  • ES6
var options = {
  query: {name: 'test'},
  headers: {Authorization: 'test'}
};
Scandit.Http.get('http://www.example.com/api/test', options)
  .then(function(response) {
    console.log(response);
    // do something with the response ...
  })
  .catch(function(reason) {
    // the request failed ...
  });
const options = {
  query: {name: 'test'},
  headers: {Authorization: 'test'}
};
Scandit.Http.get('http://www.example.com/api/test', options)
  .then(response => {
    console.log(response);
    // do something with the response ...
  })
  .catch(reason => {
    // the request failed ...
  });

(static) post(url: string, options?: object): Promise

Performs an HTTP POST request

Parameters:
Name Type Attributes Default Description
url string

Request url

options object <optional>
{}

Request options (same as Scandit.Http.request)

Properties
Name Type Attributes Description
body string <optional>

The body as a string, for example JSON

query object <optional>

Request query parameters (aka. query string)

headers object <optional>

Additional request headers. E.g. {authorization: 'Basic xxxxx'}

files object <optional>

Creates a multipart form upload POST request to send one or more files. E.g. {filename1: '/file/is/here.txt', filename2: '/another.png'}

formData object <optional>

Form body payload (will be sent together with files if provided)

timeout integer <optional>

Request timeout in seconds

connectionTimeout integer <optional>

Connection timeout in seconds

Returns:
Examples
  • JavaScript
  • ES6
var options = {
  files: {filename1: filePath}, // assuming that filePath is defined
  headers: {Authorization: 'test'}
};
Scandit.Http.post('http://www.example.com/api/test', options)
  .then(function(response) {
    console.log(response);
    // do something with the response ...
  })
  .catch(function(reason) {
    // the request failed ...
  });
const options = {
  files: {filename1: filePath}, // assuming that filePath is defined
  headers: {Authorization: 'test'}
};
Scandit.Http.post('http://www.example.com/api/test', options)
  .then(response => {
    console.log(response);
    // do something with the response ...
  })
  .catch(reason => {
    // the request failed ...
  });

(static) put(url: string, options?: object): Promise

Performs an HTTP PUT request

Parameters:
Name Type Attributes Default Description
url string

Request url

options object <optional>
{}

Request options (same as Scandit.Http.request)

Properties
Name Type Attributes Description
body string <optional>

The body as a string, for example JSON

query object <optional>

Request query parameters (aka. query string)

headers object <optional>

Additional request headers. E.g. {authorization: 'Basic xxxxx'}

files object <optional>

Creates a multipart form upload POST request to send one or more files. E.g. {filename1: '/file/is/here.txt', filename2: '/another.png'}

formData object <optional>

Form body payload (will be sent together with files if provided)

timeout integer <optional>

Request timeout in seconds

connectionTimeout integer <optional>

Connection timeout in seconds

Returns:
Examples
  • JavaScript
  • ES6
Scandit.Http.put('http://www.example.com/api/test', {body: requestBody}) // assuming requestBody is defined
  .then(function(response) {
    console.log(response);
    // do something with the response ...
  })
  .catch(function(reason) {
    // the request failed ...
  });
Scandit.Http.put('http://www.example.com/api/test', {body: requestBody}) // assuming requestBody is defined
  .then(response => {
    console.log(response);
    // do something with the response ...
  })
  .catch(reason => {
    // the request failed ...
  });

(static) request(method: string, url: string, options?: object): Promise

Performs an HTTP request

Parameters:
Name Type Attributes Default Description
method string

Request method, e.g. 'GET'

url string

Request url

options object <optional>
{}

Request options

Properties
Name Type Attributes Description
body string <optional>

The body as a string, for example JSON

binaryFile object <optional>

Sets the body to the content of the specified file with a content type of 'application/binary' E.g. '/file/is/here.png'

query object <optional>

Request query parameters (aka. query string)

headers object <optional>

Additional request headers. E.g. {authorization: 'Basic xxxxx'}

files object <optional>

Creates a multipart form upload POST request to send one or more files. E.g. {filename1: '/file/is/here.txt', filename2: '/another.png'}

formData object <optional>

Form body payload (will be sent together with files if provided)

timeout integer <optional>

Request timeout in seconds

connectionTimeout integer <optional>

Connection timeout in seconds

Returns:
Examples
  • JavaScript
  • ES6
Scandit.Http.request('GET', 'http://google.com').then(function(result) {
  console.log(result);
}).catch(function(reason) {
  console.warn('An error happened', reason);
});
Scandit.Http.request('GET', 'http://google.com').then(result => {
  console.log(result);
}).catch(reason => {
  console.warn(`An error happened, because "${reason}"`);
});

Type Definitions

Request

Properties:
Name Type Description
method string
url string
body string
params object
formData object
headers object
timeout integer
connectionTimeout integer
maxRetries integer
retryInterval integer
retryStatusCodes integer
retryStatusCodes string[]
tag string

Response

Properties:
Name Type Description
status integer
body string
headers object