Namespace: Http

Http

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
url string The URL of the HTTP request.
hideAlertError boolean <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
url string The URL of the HTTP request.
hideAlertError boolean <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
url string The URL of the HTTP request.
data Object Params for the call.
format string <optional>
"form" See `sendWithFormat`. For most TM APIs, leave blank.
cancelPromise Promise A promise that should abort the request when resolved.
disableErrorAlert boolean <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
url string
data Object
format string <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
method string
url string
data Object
hideAlertError boolean <optional>
If `true`, an alert box will *not* appear when a HTTP error occurs.
Returns:
Returns the response body.
Type
Promise.<data>