Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

REST and some unknown verbs

by Pascal Opitz on June 28 2006, 06:27

I started off with a little google search and had a read about Building Web Services the REST Way which made clear to me that you could POST something to its already given URL as a natural way of updating ressources.

A bit further down the list there was a very interesting article called How I explained REST to my wife… that initially came across a bit stupid, but then in the end flagged up some very true points about the benefits that HTTP and REST has, mentioning GET, POST and PUT …

Hang on, PUT? What the heck is that? Yet another google search and I knew a bit more:

The “PUT” method is similar to the POST method in that it can cause information to be updated on the server. The difference is that the POST method is normally handed a script which is explicitly named by the resource (that is, something that already exists), while a PUT request could be directed at a resource which does not (yet) exist. Another difference is that the POST method can be used in response to a form, while the PUT method can only contain a single data item. The PUT method is suited for publishing pages.

Seems like I discovered a verb that was unknown to me up to this point. Same was DELETE as http method mentioned in this article.
Time to look up the whole family I thought, and according to the w3c you have even more methods.
Also there is a mod_put for apache utilizing the PUT and DELETE method.

Amazingly I never came accross them, and that is in 5 years+ of proramming web applications. Am I the only guy missing out on these basic HTTP definitions?


  • Pretty interesting read that “How I explained REST to my wife”. It reminds me of the Atom Publishing Protocol which is currently a draft at the IETF which is using GET, PUT, POST, and DELETE everywhere in order to manage ressources. It’s true that these verbs aren’t used as much as they should, and that’s probably because everyone has been busy working within the limitations of the browser. You can’t PUT, or DELETE from a browser.

    by Michel Fortin on June 27 2006, 22:25 - #

  • Unfortunately, too many web “experts” are oblivious to the less common REST methods. I’ve been using them for years, and ensure all my apps are coded in a REST-ful way.

    Seems as though its made my life much easier, as I don’t think about the same problems as most people when developing.

    One thing to remember about the difference between PUT and POST – PUT does exactly what it says on the tin – it is supposed to PUT a resource onto the server/target. Simple.

    POST, however, has become confused. Essentially, it is meant to POST an update to the server, updating a specific resource, a list, or database. Its meant as a catch-all when one of the other methods won’t do.

    So, to PUT something, you’d use <form method=”put” action=”/path/to/resource/dir/”>... whereas POST would point to the resource to be updated: <form method=”post” action=”/path/to/resource.ext”>

    However, just like GET, it has become misused by the web community at large. Just like some developers use GET to post updated information to a server (causing a whole host of problems with web “caching” software – see google cache), they use POST to put a new resource online.

    Lets hope this practice is forgotten sooner rather than later.

    One of the more useful methods of REST is HEAD, where you can get information about a resource without actually GETting the resource. This is useful in confirming updates/changes to a file made from another source or finding out whether a resource exists before updating it.

    A really useful resource is the HTTP/1.1 spec:
    This gives you information on all the HTTP methods, plus all the response codes that can be issued/expected from the server.

    If you’re interested, refactored is a RESTful framework I’m developing which has a few additional features not seen in most frameworks… keep your eye out for its first release!

    by refactored on June 28 2006, 03:57 - #

  • While most browsers and server plateforms supports the 4 HTTP verbs, it is not always easy to find good information on how to use them.

    For instance, PHP assumes that a POST always contains form data ($_POST is an associative array of field name/value pairs). If you want to POST something that is not a a form (a XML document for instance), you’ll have to resort to the rather obscure file_get_contents(‘php://input’) to get the raw data from the POST request.

    Also, you may want to take a look at Freja ( ) – Framework for REstful Javascript Applications.

    Applications built on Freja:
    1. Run in the browser.
    2. Use XML for data and DOM for data manipulation.
    3. Use XSL for interface templates and client-side XSLT for interface rendering.
    4. Are server-side agnostic. They communicate with RESTful web services using asynchronous HTTP requests. PUT and DELETE verbs are supported since version 2.0

    Freja is not a server-side framework but there are a couple sample server-side scripts that show how to build PHP RESTful web services

    by Cedric on June 28 2006, 10:37 - #

  • Dude, I went through the same thing like two months ago with REST. I hate acronyms.

    by Dustin Diaz on June 29 2006, 11:35 - #

  • I had no idea about PUT or DELETE! Never heard of them and never used them… Since I don’t do much server side development I shouldn’t be all that surprised that I’ve not used them but, like Pascal, I can’t believe that I’ve never even heard of them!

    by Mike Stenhouse on June 29 2006, 16:51 - #

  • Michel:
    Actually, some Browsers do support PUT and DELETE as well, at least using javascript’s xmlhttprequest. As far as I know are Mozilla based browsers and IE perfectly fine with it. Not sure about Opera, but I know that Safari doesn’t like it.

    Also, php’s php://input will happily accept any sent information in POST as well as PUT and DELETE. I’m sure HEAD is fine, too.

    by Matthias on July 4 2006, 10:40 - #

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p