Skip to content

GET Request Entity Body Overview

mikeobrien edited this page Sep 14, 2010 · 5 revisions

The current release of the WCF REST API does not allow you to receive an entity body with a GET request. This is done for a reason (As noted below) but may be an unnecessary restriction in some circumstances. WCF REST Contrib automatically removes this limitation when you use the WCF REST Contrib WebServiceHost described under WebServiceHost Overview.

There are some cases where sending an entity body with a GET request can be useful. For example lets say I have the following resource:

http://services.library.com/books

In this example we have the requirement that users be able to pass complex filtering with multiple conditional expressions to filter the books returned. In that case it’s not reasonable to pass those in path segments or in the querystring because they will be unwieldy. Instead you can pass an entity body containing the filter.

RFC 2616 which outlines HTTP 1.1 neither explicitly allows (As it does for POST and PUT) or disallows an entity body in a GET request (See here and here). It only specifies that GET should be used to retrieve an entity and it must be safe and idempotent. Leonard Richardson (Coauthor of RESTful Web Services) mentioned two reasons why you would not want to do this. First, since the behavior is not explicitly defined you cannot predict the behavior of elements on the web that are handing the request. For example some firewalls or proxy’s could drop the entity body of a GET request altogether. Second the response cannot be cached since current caching products do not examine an entity body of the GET request. He mentioned an alternative could be passing the entity body via the querystring, putting it in a custom header and note that header in the Vary header or just POSTing it. In any event you will need to take these things into consideration when deciding to pass the entity body in a GET (Or DELETE) request. If you do not need to cache the results and you know the network environment in which the service is running and being consumed will pass the entity body in a GET request this will probably be ok. If your service will be exposed on the web and/or you need GET results to be cached you will run into trouble.

NOTE: A feature request has been submitted to Microsoft to add an option to enable or disable this in the WCF REST API. See more here.