I'm using Angular's $http
service to make web api requests. When I use the GET method, the two param values are added to the query string:
// http://foo.com/api/test?heroId=123&power=Death+ray $http.get("/api/test", { params: { heroId: 123, power : "Death ray" } })
However, when I use the PUT method the params are JSON-encoded and sent as the request payload:
// {"params":{"heroId":123,"power":"Death ray"}} $http.put("/api/test", { params: { heroId: 123, power : "Death ray" } })
How can I force the params to be added to the query string when using PUT?
Is it OK to use query parameters in a PUT request? Absolutely. Query parameters are just another piece of the resource identifier.
You can send data to the server in the body of the HTTP PUT request. The type and size of data are not limited. But you must specify the data type in the Content-Type header and the data size in the Content-Length header fields. You can also post data to the server using URL parameters with a PUT request.
In Mule 4 in the Request section of the HTTP request connector in Mule 4 under the Query Parameters tab, we can specify the name and the value for the Mulesoft query parameters that we are going to send (Refer to Figure 1).
Are parameters which are sent by PUT passed in the URL, or in the HTTP header ? Not the headers. It's the same as POST - either the URL or the body of the request. The only difference is the HTTP verb being used and of course the semantics that come with it (UPDATE a resource on the server).
With $http.put
, $http.post
or $http.patch
, the config object containing your url parameters goes as the third argument, the second argument being the request body:
$http.put("/api/test", // 1. url {}, // 2. request body { params: { heroId: 123, power : "Death ray" } } // 3. config object );
$http.put
documentation for reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With