Aravind Yarram
Aravind Yarram

Reputation: 80192

handling DELETE in REST

I have the resource uri as /avl/leagues/leagueName. Idea is to delete the league with the provided name in a restfull way. I tried the below but the browsers are always sending a GET instead of the DELETE. Any ideas why? I am using Tomcat on server side.

<form action="/avl/leagues/Cccccc" method="DELETE">
   <input type="submit" value="Cancel league">
</form>

Upvotes: 1

Views: 145

Answers (2)

cHao
cHao

Reputation: 86585

HTML forms only officially support GET and POST for submitting.

Typically, people work around that limitation by either sending the request via Ajax, or including a hidden field in the form to tell the server-side code to treat this request as if it were a DELETE rather than a GET. (Of course, the server-side code has to know to look for that field and act accordingly.)

Upvotes: 4

JB Nizet
JB Nizet

Reputation: 692231

Browsers are not very good restful clients. They basically use POST and GET for forms, and that's all.

The Spring MVC form tag library allows specifying DELETE as the method, IIRC, and will in fact add a hidden field to the form telling the server that, although the method is not really a DELETE (because the browser is not able to send such requests), it should be treated by the server as a DELETE (thanks to a filter). See Using PUT and DELETE methods in Spring MVC for a similar question and its answer.

Upvotes: 2

Related Questions