Consuming REST services with HttpClient

If we have an app that displays data, the chances are that it comes from somewhere outside the device, say somewhere like the Internet.

Getting ready

To work with JSON responses, we need to install the Newtonsoft.Json NuGet package or the Json.NET component. This is an advanced JSON parser; however, we can make use of the DataContractJsonSerializer type or any other serializer for JSON.

How to do it...

In order to obtain data from the Internet or a local network, we use HTTP requests. In this recipe, we access data from

  1. Access JSON data from the HTTP location in the form:
    { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati", "body": "quia ...

Get Xamarin Mobile Development for Android Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.