How to handle PUT and DELETE HTTP methods?

116 views
Skip to first unread message

André Miranda Moreira

unread,
May 6, 2014, 8:59:57 PM5/6/14
to res...@googlegroups.com
I looked at the documentation of Hunchentoot and it doesn't mention the PUT or the DELETE method.

In the (old) RESTAS documentation, it says that the DEFINE-ROUTE macro can handle both PUT and DELETE methods.

I believe it may be an inapropriate question, since it is more about the web server than about RESTAS, but I couldn't find any other reference.

What would be the equivalent HUNCHENTOOT:GET-PARAMETERS for PUT and DELETE?

Daimrod

unread,
May 6, 2014, 9:21:56 PM5/6/14
to res...@googlegroups.com
André Miranda Moreira <andrem...@gmail.com> writes:
Hi,
It's been a long time since I've used Restas but IIRC I used to parse
TBNL:GET-PARAMETERS*.

--
Daimrod/Greg

André Miranda Moreira

unread,
May 6, 2014, 11:14:36 PM5/6/14
to res...@googlegroups.com
How can I make it work?

(define-route put-teste ("puttest" :method :put)
  (hunchentoot:get-parameters*))

The HUNCHENTOOT:GET-PARAMETERS* simply returns nil...

Thanks for your diligence.

Orivej Desh

unread,
May 6, 2014, 11:23:41 PM5/6/14
to res...@googlegroups.com
> What would be the equivalent HUNCHENTOOT:GET-PARAMETERS for PUT and DELETE?

If PUT and DELETE bodies contain form data, push :PUT and :DELETE into
*METHODS-FOR-POST-PARAMETERS* and use POST-PARAMETER. Otherwise, get
the content body with RAW-POST-DATA and parse it as needed.
Documentation for that function even mentions: "Note that this function
is slightly misnamed because a client can send content even if the
request method is not POST."

André Miranda Moreira

unread,
May 9, 2014, 2:45:36 AM5/9/14
to res...@googlegroups.com
I've been trying to make it work, but I couldn't.

The moment the app redirects to the PUT route, the params are passed in the URL (just like a GET method), and the server says that the route is undefined.

(define-route test/put ("put" :method :put)
  (list :body (<:div (hunchentoot:post-parameter "paramtest"))))

When the app redirects to this route, the URL shows localhost/put?paramtest=123

And I have already modified the *METHODS-FOR-POST-PARAMETERS*:
(pushnew :put hunchentoot:*methods-for-post-parameters*)
(pushnew :delete hunchentoot:*methods-for-post-parameters*)

How can I make it work?

Orivej Desh

unread,
May 9, 2014, 6:20:06 AM5/9/14
to res...@googlegroups.com
> I've been trying to make it work, but I couldn't.
>
> The moment the app redirects to the PUT route, the params are passed in the
> URL (just like a GET method), and the server says that the route is
> undefined.

The route is undefined because you are redirecting to GET. You can
confirm that in the browser console.

> (define-route test/put ("put" :method :put)
> (list :body (<:div (hunchentoot:post-parameter "paramtest"))))

> When the app redirects to this route, the URL shows
> localhost/put?paramtest=123

Ary you trying to redirect from one PUT route to another? If not, that
is not possible with HTTP. In general, you should only redirect to GET.
How do you perform the original PUT request? E.g. with jQuery that
would be jQuery.ajax('/put', {type: 'PUT', data: {paramtest: 123}})
If you do not perform PUT requests at all, please describe what you
are trying to accomplish.
Reply all
Reply to author
Forward
0 new messages