Reputation: 2130
I am doing a little proof of concept/template app using Spring MVC. I have been asked to use GET, POST, PUT and DELETE in specific circumstances. I have managed this now with a lot of help from this forum.
My concern at this stage is that the only way I could work out to send a DELETE call was to add a second form to my jsp page with a DELETE method. As a proof of concept I added a delete to the edit page which looks something like this...
//Edit Form
<form:form method="PUT" modelAttribute="person" action="${pageContext.request.contextPath}/person/${person.id}" >
// fields
<input type="submit" value="Save and continue"></input>
</form:form>
//DELETE FORM
<form:form method="DELETE" modelAttribute="person" action="${pageContext.request.contextPath}/person/${selectedOpportunity.id}" >
<input type="submit" class="btn btn-success btn-lg" value="Delete"></input>
</form:form>
This works nicely - both deleting and editing. My concern is as an overarching approach it is a bit restrictive. As we get further into proper requirements and design I may need to be more flexible - for example have a list of objects with edit & delete buttons next to them e.g.
Mr Bob Baines [edit] [delete]
Ms Clara Dumont [edit] [delete]
...
I don't think I can do this using my current approach and I see the possibility that the design will slowly become more and more convoluted and twisted to follow what I am able to do technically rather than what is actually required.
I have seen a couple of ways (on this forum mainly) to use javascript and jquery to send a delete http request but I am being actively discouraged from using javascript on the pages wherever possible. Can anyone tell me if there is a way to send a DELETE or POST from HTML manually ? Or should I be pushing back against the design requirement ? I have seen some arguments that DELETE and PUT are un-necessary as it can all be expressed with POST and form content but in broader discussions on REST architecture their use seems to be considered a standard approach?
Upvotes: 0
Views: 926
Reputation: 943591
HTML forms can send POST or GET requests. Everything else in HTML can only send GET requests (unless the browser caching rules causes it to automatically make a HEAD request to check for freshness).
The only way to trigger any other kind of HTTP method from an HTML document is through JavaScript or plugins.
Upvotes: 1