These days RESTful web services are all the buzz, even though many who think they know what that means don't have a clue. But if you want to build a truly RESTful web app to go with your RESTful web services you'll quickly learn that web browsers only support GET and POST in HTML forms. Plack::Middleware::HttpMethodTunnel to the rescue after the jump.

Plack::Middleware::HttpMethodTunnel gets around this limitation by allowing you to do what is called HTTP Method Tunnelling. In essence you can either submit your HTTP method as as an HTTP header or a form parameter and then just use a POST as the method.

Here's an example form:

<form method="POST">
<input type="hidden" name="X-HTTP-Method" value="DELETE">

When you enable the HttpMethodTunnel middleware this then translates the $env->{REQUEST_METHOD} from POST into whatever is stored in X-HTTP-Method, thus allowing you to tunnel any HTTP method across a normal POST operation, and a GET or HEAD across a GET operation.


Leave a comment

About JT Smith

user-pic My little part in the greater Perl world.