Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

[$http transformRequest] : data cannot be modified in transformRequest #11277

Closed
GabrielDelepine opened this issue Mar 9, 2015 · 4 comments
Closed

Comments

@GabrielDelepine
Copy link

Issue : http://jsfiddle.net/uqr74s7g/4/

transformRequest doesn't receive the data in case of a GET request (first parameter is always undefined).

For POST request, the same code works as expected. I tried with the branch 1.2.x, 1.3.x, 1.4.x

Maybe it's a "normal" behaviour but in this case I'd like to know why. The documentation never mention that.

Thanks

@Narretz
Copy link
Contributor

Narretz commented Mar 9, 2015

When you create a resource action with the GET method, you don't get to set the request body, only the request parameters, see here: https://code.angularjs.org/1.3.14/docs/api/ngResource/service/$resource#usage So it makes sense that you cannot use transformRequest with a body.
Sending a request body with a GET request, is kind of an edge case, as it is possible but not very useful in most cases - as far as I understand from this here Stackoverflow answer for example: http://stackoverflow.com/a/983458/787333

I assume we could add the possibility to add a request body to GEt requests, but it's probably not very useful.

@GabrielDelepine
Copy link
Author

In my case it seams to be a GET that I need : I get a list from an API and the parameters are some optional filters (example : /products?type=1&region=3).
I need to format the query from a complexe object which is made with ngForm, that's why i'd like to proceed it in the transformRequest statement.

@GabrielDelepine
Copy link
Author

Feedback : TansformRequest make sense to send an array through a GET query when the backend expect foo[]=1&foo[]=2 instance of foo=1&foo=2.

As @pkozlowski-opensource said here : Adding [] (to the key name) is definitively and option, just a bit of pain when you've got your object ready.

Releated to #3740

@pkozlowski-opensource
Copy link
Member

@yappli there is not much point in sending GET requests with body, see http://stackoverflow.com/a/983458, so the current $resource behavior is correct here.

On the other hand formatting request params with [] is not much easier after 6c8464a landed.

Closing, as I don't think there us anything actionable here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants