Do I use PUT?

100 views
Skip to first unread message

Indu

unread,
Sep 13, 2012, 10:43:31 AM9/13/12
to api-...@googlegroups.com
Hi all,

      I m working on developing api and I ve read in some article that PUT shall be used for complete replacement.But while referring to some API docs,they don't use PUT anymore though they have used the same in their previous version and it was replaced by POST(/resources/id) or PATCH(for partial updation)? And I m confused whether to use PUT or I will go with POST? And curious to know about the difference in using POST and PUT for updation?

Thanks for looking into this

Thanks & Regards,
Indu

Ian Joyce

unread,
Sep 13, 2012, 10:54:49 AM9/13/12
to api-...@googlegroups.com
You can read the relevant bits of the spec here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

But generally speaking PUT is for creating a resource and POST is for
updating a resource.


--Ian
> --
> You received this message because you are subscribed to the Google Groups
> "API Craft" group.
> To unsubscribe from this group, send email to
> api-craft+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/api-craft?hl=en.
>
>

Enrique Amodeo

unread,
Sep 13, 2012, 10:56:27 AM9/13/12
to api-...@googlegroups.com
Hi Indu, the answer is a bit tricky. First of all the URI must exist
before the request. Then you have several options:
a) If you want complete replacement of the state use PUT. It has the
big advantage of being idempotent. Do not use this for partial
updates.
b) If you want partial update use PATCH. Ensure to use a mime type
that has appropiate semantics (partial document, diff, ...). It isn't
idempotent, so you should use some mechanism to avoid problems with
duplicated request (if-match, etag). The problem is that it's only a
proposed standard, so most server don't understand it:
http://tools.ietf.org/html/rfc5789
c) The old way for partial updates is using POST instead PATCH. Not
standarized. Usually use the same practices that the ones used with
PATCH. It is good to add a header: "X-HTTP-Method-Override: PATCH" in
order to more modern server switch to PATCH semantics.

Cheers !

Indu

unread,
Sep 13, 2012, 11:08:57 AM9/13/12
to api-...@googlegroups.com
Thanks Joyce and Enrique

          But while I m using PUT for updating I m facing the following issue:

           1. I m not able to send the parameters in the request body,is forcing me to send it in the query parameter. I m afraid is it safe to send the write operation's parameters in query string and also the content length may exceed the allowed size of the query string if I send a large data for updation.
            2.And also tomcat is not retrieving the value if in request.getParameter while using PUT

           So I need to know whether this issue has been faced? And also why am I getting so?

Thanks and Regards
Indu

Enrique Amodeo

unread,
Sep 13, 2012, 11:40:54 AM9/13/12
to api-...@googlegroups.com
Hi Indu, the correct thing to do is to send the parameters inside the
request body, not in the URL. Probably request.getParameter will not
understand the body unless you encode them the same way you use in the
URL (use mime type "application/x-www-form-urlencoded").
I suggest you to use a JAX-RS implementation instead the plain servlet stack.
Cheers,
Enrique Amodeo

Indu

unread,
Sep 14, 2012, 1:38:49 AM9/14/12
to api-...@googlegroups.com
Enrique,

        I used the content type application/x-www-form-urlencoded for PUT still I don't get it

Thanks
Indu
Reply all
Reply to author
Forward
0 new messages