Set REST call method to PUT


#1

How does one set the Method to PUT when using the following?
I have tried appending it to the headers and calling this.http.put() but no luck.

putSomething(): Observable<Object> {
        let json = JSON.stringify({id: '12345'});
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        return this.http.put('https://somefunkedoutdomain.com/api/v1/users/:id', json, { headers: headers });
    }

Sorry, didn’t realize the code didn’t go through on the submission of this post.


#2

Did you try, do something like this:

this.http.put(url, JSON.stringify(body), { headers: headers })

??

Could you show the code?


#3

Sorry, didn’t realize the code didn’t go through on the submission of this post.
Added now.


#4

Hhh, json is request body

return this.http.put('https://somefunkedoutdomain.com/api/v1/users/' + id, json, { headers: headers });

#5

The API I am accessing requires 2 parameters however the url ends with/:id.
xr0master - your example suggests the id number is passed in the url but how would the other second required parameter get through?
I tried it. It didn’t work.


#6

It’s tough to do much with phrases like “no luck” and “it didn’t work”. Are you watching network requests? Is anything going over the wire?


#7

PUT is same like POST. All params you could send into request body (your json).

PS or use GET with /api/v1/users/:id/:foo/:bar :smile: