views:

3671

answers:

4

I'm looking into a restful design and would like to use the HTTP methods (POST, GET, ...) and HTTP headers as much as possible. I already found out that the HTTP methods PUT and DELETE are not supported from the browser.

Now I'm looking to get different representations of the same resource and would like to do this by changing the Accept header of the request. Depending on this Accept header, the server can serve a different view on the same resource.

Problem is that I don't find a way to tell my browser to change this header.

The a tag has a type attribute that can have a mime type looked like a good candidate but the header was still the browser default (in firefox it can be changed in about:config with the network.http.accept.default key).

+1  A: 

Use some javascript!

xmlhttp=new XMLHttpRequest();
xmlhttp.open('PUT',http://www.mydomain.org/documents/standards/browsers/supportlist)
xmlhttp.send("page content goes here");
James Anderson
Thank you for the fast answer but the question is about changing the default headers send in the HTTP request. In particular the Accept header.
JeroenWyseur
On a side note, the specification (http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/#dfn-open) says nothing about PUT and DELETE, see the editorial note.Also, there is no submit in that case what is nice a ajaxified user interface but otherwise not.
JeroenWyseur
+2  A: 

I don't think it's possible to do it in the way you are trying to do it.

Indication of the accepted data format is usually done through adding the extension to the resource name. So, if you have resource like

/resources/resource

and GET /resources/resource returns its HTML representation, to indicate that you want its XML representation instead, you can use following pattern:

/resources/resource.xml

You have to do the accepted content type determination magic on the server side, then.

Or use Javascript as James suggests.

Milan Novota
+5  A: 
Shonzilla
A: 

I was looking to do exactly the same thing (RESTful web service), and I stumbled upon this firefox addon, which lets you modify the accept headers (actually, any request headers) for requests. It works perfectly.

https://addons.mozilla.org/en-US/firefox/addon/967/

Chris