An alternative HTTP client for SharePoint 2013

Dec 12, 2013 at 12:57 PM
Adding the necessary headers to working with the SharePoint REST API is not difficult at all. But where does this code belong? Should it be a "plugin" for datajs or could it even be merged into the core so you can do: OData.defaultHttpClient = OData.spHttpClient for example.
var defaultClient = OData.defaultHttpClient;
    var spClient = {
        request: function (request, success, error) {
            request.headers = {
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose",
                "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
                "If-Match": "*"

            return defaultClient.request(request, success, error);
    OData.defaultHttpClient = spClient;