In my Angular app, I have a service that utilizes $http
to retrieve data from a server. The server endpoint uses HMAC authentication and expects the query string parameters to be in a specific order on the URL.
Angular sorts the $http
parameters when it builds the URL, so it doesn't seem possible to specify a custom parameter order.
Here's an example:
this.apiCall = function() {
return $http({
method: 'GET',
url: 'http://example.com/url/v1/endpoint',
params: {
'c': 'cdata',
'a': 'adata',
'b': 'bdata'
}
});
};
Angular will build the URL as http://example.com/url/v1/endpoint?a=adata&b=bdata&c=cdata
, but I need to preserve the order of the params as specified, http://example.com/url/v1/endpoint?c=cdata&a=adata&b=bdata
.
I realize I could just tack on the parameters to the URL string manually, but that is not very friendly and it doesn't allow for easy management in $http
interceptors.
Angular probably sorts the parameters to keep a uniform behavior across browser implementations, as object ordering is not specified in ECMAScript.
Regardless, does anyone know how to work around the default Angular behavior of sorting the params in order to build a URL that preserves the parameters as specified?