views:

143

answers:

2

Hi,

I've read several posts in the internet about that Silverlight only supports GET and POST, and that the most of the web browsers too. Is this true? has it changed lately? I'm developing a RESTful web service for a Silverlight application, still in early stage, and I'd like to know if I should use just POST and GET, or otherwise I could use PUT and delete.

Cheers

+2  A: 

Generally the other verbs are blocked in some way between your browser and your server. If you are implementing REST correctly, you will definitely need access to PUT and DELETE.

You can place the verb you want to use in an additional header, that then replaces the GET verb just before the web service is called. Use the x-http-method-override header to do this as well as something like the WCF Rest starter kit which has code to do the conversion of the verb:

http://www.msdev.com/Directory/Description.aspx?eventId=1316

James Westgate
Curiously, there are thousands of web sites that are perfectly RESTful and yet web browsers only support GET and POST. Fielding has said quite specifically on REST-DISCUSS that GET and POST are sufficient.
Darrel Miller
@Darrel - link please. Having implemented quite a few REST services I would find this both annoying and non-restful.
James Westgate
I'll find you the link, but in the meanwhile, can you tell me what REST constraint is being violated?
Darrel Miller
www.acme.com/widgets/1 (GET) - that will get a widget. Now tell me how I am supposed to DELETE that widget, or differentiate between an insert and an update.
James Westgate
When you say: "Generally the other verbs are blocked in some way between your browser and your server." what do you mean? does that mean that even if I get to make work PUT and DELETE still there is something blocking them in the path? why? :S
vtortola
Yes, both firewalls and potentially the server itself (IIS etc) will not be configured to accept those verbs. Not so much a problem client side in my experience.
James Westgate
@James See my answer to this question about the need for PUT and DELETE http://stackoverflow.com/questions/2832901/overwrite-http-method-with-jax-rs/2834242#2834242
Darrel Miller
@James POST /WidgetTrashCan?url=/widgets/1
Darrel Miller
@James I'm confused by your request for me to use HTTP verbs to differentiate between insert and update. Considering you can create resources with PUT how can you tell if PUT /widgets/75 is doing an update or an insert? You cannot assume that POST is inserting and PUT is updating.
Darrel Miller
Start by look at http://en.wikipedia.org/wiki/Representational_State_Transfer where POST commonly defines an insert and PUT an update. Remember the URI is the resource, the verb is the action. The beauty of REST is that it is non prescriptive, you are not forced to use these verbs, but its considered poor form if the resource contains the action /deletewidget/1 or widget/1/?action=update
James Westgate
@Darrel - regarding your quote from Roy Fielding, I believe that is taken in the context of a wiki, where a GET and a POST may be sufficient.
James Westgate
@James Even Wikipedia specifically states for PUT "Update the addressed member of the collection, or if it doesn't exist, create it." You are correct the URIs you suggest would be poor form. The URI I suggested on the other hand indicates that you are adding a widget into a "trash can". This is a natural metaphor for deleting something, and the operation is completely consistent with the semantics of POST.
Darrel Miller
@James Roy's quote explicitly says that he is using a Wiki as an example. He also says `There are plenty of RESTful services that do nothing but GET and POST`. How is that statement consistent with your statement `If you are implementing REST correctly, you will definitely need access to PUT and DELETE.`?
Darrel Miller
Let me rephrase to be clear. "If you are implementing REST and you need to perform an update or delete operation, then you will need access to verbs PUT and DELETE if you want to be semantically correct." Whilst the trash can example may bypass the need for a DELETE verb in this instance for me it is far more intuitive to stick to one URI and use different verbs. This is the essence of REST, the URI is the resource and the verb is the action. But of course if a trash can is required (the same as a move-to-folder) operation then this is in-fact a nice solution.
James Westgate
Finally,I did actualy consider than if you use a custom X- header to send DELETE or PUT verbs you could very well create your own verbs! Such as eg MOVE. Im not saying this is a good/bad idea though .. merely another interesting point for discussion.
James Westgate
Article I just read about verb confusion: http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/
James Westgate
+1  A: 

When using the Browser HTTP stack only GET ans POST are supported. However the Client HTTP stack provided by Silverlight itself can send other verbs such as PUT. Hence it is possible to consume a typicall RESTFul API in Silverlight.

AnthonyWJones
Yes, it seems you're right:http://msdn.microsoft.com/en-us/library/dd920295%28VS.95%29.aspx
vtortola