xamarin/Xamarin.Auth — pull request #28 by gaearon (2013-06-04 20:42:44+00:00)
Title: Make request body configurable for service implementors and accessible from outside

We're using this to implement Facebook batch requests.
This is roughly how we use it:

public Request CreateBatchRequest (params Request [] requests)
{
var session = EnsureLoggedIn ();
JArray jsonRequests = new JArray ();

foreach (var request in requests) {
var jsonRequest = new JObject {
{"method", request.Method},
{"relative_url", BaseUri.MakeRelativeUri (request.Url).ToString ()}
};

var body = request.GetRawBody (); // HERE
if (body.Length > 0)
jsonRequest ["body"] = body;

jsonRequests.Add (jsonRequest);
}

var batchRequest = session.Service.CreateRequest ("POST", BaseUri, session.Account);
batchRequest.Body = "batch=" + jsonRequests.ToString (); // AND HERE

return batchRequest;
}

Docs on batch requests:

https://developers.facebook.com/docs/reference/api/batch/

We didn't want to subclass `Request` and opted for keeping `Body` public because we want to make it **implementation-independent**, i.e. both `FacebookService` and `Facebook6Service` (that uses iOS 6 Social.framework) can be used with this code.