Communicating with a JSON based REST service is a task that many Windows Phone apps have to do. My apps sure do it a lot so I came up with a base class that I use in all of them, put it on Github and created a Nuget package, so your apps could use it to.
The usage of this base class is simple. Create your service class and inherit from BaseRestService. The minimum you need to do to make it work is to override the GetBaseUrl() method to set the base url for all the requests. You can (but do not have to) also override the GetRequestHeaders() method to set the default request headers.
public class MyDataService: BaseRestService
{
protected override string GetBaseUrl()
{
return "my base url";
}
protected override Dictionary<string, string> GetRequestHeaders()
{
return new Dictionary<string, string>
{
{"Accept-Encoding", "gzip, deflate"},
{"Accept", "application/json"},
};
}
}
and you can now use the following protected methods
[Read More]