Configuring Request

The standard request options provided out of the box are not enough considering the following scenarios.

• Add some authorization headers for your request
• Change how caching is handled for the request
• Transform the request going out, or the response coming in, in certain set ways

In such cases, you can configure your request further through the optional configuration object passed to the requests as below.

$http(config)
What follows is a basic pseudo-code template for calling this method:
$http({
method: string,
url: string,
params: object,
data: string or object,
headers: object,
transformRequest: function transform(data, headersGetter) or
an array of functions,
transformResponse: function transform(data, headersGetter) or
an array of functions,
cache: boolean or Cache object,
timeout: number,
withCredentials: boolean
});

The GET, POST, and other convenience methods set the method, so you don’t need to. The config object gets passed in as the last argument to $http.get, $http.post, so you can still use it while using any of the convenience methods. You can change the request being made by passing the config object set with the following keys:


ParameterDescription
methodA string representing the HTTP request type, like GET, or POST
urlA URL string representing the absolute or relative URL of the resource being requested
paramsAn object (a map to be precise) of string-to strings, representing keys and values that will be translated to URL parameters. For example: [{key1: 'value1', key2: 'value2'}] would be converted to: ?key1=value1&key2=value2 after the URL. If we use an object, instead of a string or a number, for the value, the object will be converted to a JSON string.
dataA string or an object that will be sent as the request message data
timeoutThe time in milliseconds to wait before the request is treated as timed out There are a few more options that can be configured.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +