Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you send anything beside GET and POST from browser to your RESTful app?

Tags:

rest

http

I am not gettng the RESTful thing. Yes, I know how to send a GET request to my app from my browser. It's through URL linking.

<a href="/user/someone">

And can also send POST requests through form method.

<form method="post">

Beside that I know browsers sometimes send HEAD command to figure out page status, but on which the end user has no control.

Then what are those DELETE and PUT commands I am reading of? How do you send, for example a DELETE command from your browser to your RESTful application?

like image 780
CDR Avatar asked Mar 22 '09 16:03

CDR


2 Answers

The HTML 4.01 specification describes only GET and POST as valid values for the method attribute. So in HTML there is no way of describing other methods than this by now.

But the HTML 5 specification (currently just a working draft) does name PUT and DELETE as valid values.

Taking a look into the XMLHttpRequest object specification (currently just a working draft too) used for asynchronous requests in JavaScript (AJAX), it supports the PUT and DELETE methods too, but doesn’t say anything about the actual support by current browsers.

like image 106
Gumbo Avatar answered Oct 05 '22 02:10

Gumbo


To simulate PUT and DELETE, frameworks like Rails instead build forms like this:

<form action="/users/1/delete" method="post">
    <input type="hidden" name="_method" value="delete" />
    <input type="submit" value="Delete user 1" />
</form>

This is actually a POST form, but using the hidden _method input to tell the server which method was really intended. You could implement this support on any other web framework as well.

like image 45
Ron DeVera Avatar answered Oct 05 '22 02:10

Ron DeVera