Building a RESTful http client for a PCL
<p><strong>Context</strong></p>

<p>Recently I started working on a mobile project using Xamarin which works with C#/.NET. I came from developing android apps and Java development in general. I always use the same scheme when I build the http client in an app which is <a href="https://stackoverflow.com/a/19393551/1403997">this</a>. I like the concept of overriding only if It's neccesary. I'd like to translate this Java RESTful http client to a C#/.NET RESTful http client. </p>

<p>I'd like to have an API that looks like this:</p>

<pre><code>await MakeGetRequest&lt;List&lt;Role&gt;&gt;(Constants.RolesEnpoint)
            .OnSuccess((response) =&gt;
            {
                //Response which is of type List&lt;Role&gt;
                ShowList(response);
            })
            .OnError((exception) =&gt;
            {
                ShowErrorMessage("Unkown error:" + exception.Message);
            })
            .OnInternatServerError(() =&gt;
            {
                ShowErrorMessage("The server explode");
            });
</code></pre>

<p>And well, mainly the problem that I'm facing is that I'm not really sure about how to implement those lambda callbacks. What I've done so far is:</p>

<pre><code>    //&lt;summary&gt;
    // Makes a get request and deserializes the result JSON as T class objects.
    // Check https://forums.xamarin.com/discussion/22732/3-pcl-rest-functions-post-get-multipart
    //&lt;/summary&gt;
    //&lt;param name="endpoint"&gt;The endpoint name i.e. "/api/v1/feed"&lt;/param&gt;
    //&lt;param name="auth"&gt;True if we want to seth the AUTH_TOKEN cookie. False otherwise.&lt;/param&gt;
    private async RequestTask&lt;T&gt; MakeGetRequest&lt;T&gt;(string endpoint, bool auth = true)
    {
        await new RequestTask&lt;T&gt;((rt) =&gt;
        {
            try
            {
                ValidateAuthToken();
                var request = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress, endpoint));
                SetHeaders(request);
                if (string.IsNullOrEmpty(authToken))
                {
                    rt.OnAuthTokenError();
                }
                request.Headers["Cookie"] = authToken;
                request.Method = "GET";

                HttpWebResponse response = await request.GetResponseAsync();

                if (!response.StatusCode.Equals(HttpStatusCode.OK))
                {
                    rt.OnHttpError(response.StatusCode);
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.Forbidden:
                            rt.OnForbidden();
                            break;
                        case HttpStatusCode.InternalServerError:
                            rt.OnInternalServerError();
                            break;
                        case HttpStatusCode.RequestTimeout:
                            rt.OnRequestTimeout();
                            break;
                        case HttpStatusCode.GatewayTimeout:
                            rt.OnGatewayTimeout();
                            break;
                        case HttpStatusCode.NotFound:
                            rt.OnNotFound();
                            break;
                        case HttpStatusCode.Unauthorized:
                            rt.OnUnauthorized();
                            break;
                    }
                }

                var respStream = response.GetResponseStream();
                respStream.Flush();

                using (StreamReader sr = new StreamReader(respStream))
                {
                    //Need to return this response 
                    string strContent = sr.ReadToEnd();
                    respStream = null;
                    rt.OnSuccess(JsonConvert.DeserializeObject&lt;T&gt;(strContent, dateTimeConverter));
                }
            }
            catch (Exception e)
            {
                rt.OnError(e);
            }
        });
    }
</code></pre>

<p>I don't want a concrete answer, or a full-code answer, just being pointed out in the right direction.</p>