Wrap the core $http service to return normal promises, plus provide extra capabilities around parameter encoding (e.g. multipart form)
Methods
-
Http.delete(url [, hideAlertError])
-
Wrapper around `$http.delete`.
Parameters:
Name Type Argument Description urlstring The URL of the HTTP request. hideAlertErrorboolean <optional>
If `true`, an alert box will *not* appear when a HTTP error occurs. Returns:
Returns the response body.- Type
- Promise.<data>
Examples
Send a DELETE request.
Http.delete("http://example.com") .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors });Don't display an error if a HTTP error occurs .
Http.delete("http://example.com" true) .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors }); -
Http.get(url [, hideAlertError])
-
Wrapper around `$http.get`.
Parameters:
Name Type Argument Description urlstring The URL of the HTTP request. hideAlertErrorboolean <optional>
If `true`, an alert box will *not* appear when a HTTP error occurs. Returns:
Returns the response body.- Type
- Promise.<data>
Examples
Send a GET request.
Http.get("http://example.com") .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors });Don't display an error if a HTTP error occurs .
Http.get("http://example.com" true) .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors }); -
Http.post(url, data [, format], cancelPromise [, disableErrorAlert])
-
Wrapper around HTTP POST, with optional format - defaults to form URL encoding of parameters for compatibility with TM API methods.
Parameters:
Name Type Argument Default Description urlstring The URL of the HTTP request. dataObject Params for the call. formatstring <optional>
"form" See `sendWithFormat`. For most TM APIs, leave blank. cancelPromisePromise A promise that should abort the request when resolved. disableErrorAlertboolean <optional>
If `true`, an alert box will *not* appear when an error occurs. Returns:
Returns the response body.- Type
- Promise.<data>
Example
Send a POST request.
Http.post("http://example.com", { firstName: data.firstName, lastName: data.lastName }) .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors }); -
Http.put(url, data [, format])
-
Wrapper around HTTP PUT, with optional format - defaults to form URL encoding of parameters for compatibility with TM API methods.
Parameters:
Name Type Argument Default Description urlstring dataObject formatstring <optional>
"form" Format for encoding parameters: 'form' (default, as this is used often in TM) 'query' or 'body' Returns:
Returns the response body.- Type
- Promise.<data>
Example
Send a PUT request.
Http.put("http://example.com", { firstName: data.firstName, lastName: data.lastName }) .then(function(data) { // Do something... }) .catch(function(error) { // Handle errors }); -
Http.sendMultipart(method, url, data [, hideAlertError])
-
Perform multipart-form http send with the specified method, url and data
Parameters:
Name Type Argument Description methodstring urlstring dataObject hideAlertErrorboolean <optional>
If `true`, an alert box will *not* appear when a HTTP error occurs. Returns:
Returns the response body.- Type
- Promise.<data>