In this article, we will see how to consume a REST service in Windows 10. Before that we will introduce REST services.
REST is a resource that implements a uniform interface using standard HTTP GET, POST, PUT methods that can be located by URI. Windows 10 UWP supports basic get and post web requests using the following two APIs:
The System.Net.Http.HttpClient was introduced in .NET 4.5. In Windows 10 this API has changed to top layer of Windows.Web.Http.HttpClient. The supported OS and programming languages are as follows:
Both of this APIs are available in UWP. Select which one you need. If you are going to develop native UI or pass specific SSL certificates for Authentication then use Windows.Web.Http.HttpClient API. If you are going to develop app with cross platform such as iOS, Android, then use System.Net.Http.HttpClient. This API sppports Xamarin IOS and Android development. Now see how to consume REST service in Windows 10 app using System.Net.Http.HttpClient. Create new windows 10 project. For POST JSON data write the following code. URI is the url you are going to POST JSON data. Here, I will create runtime JSON data using dynamic and ExpandoObject, using this you can create JSON string at runtime instead of creating classes. Json.Net are used to serialize the runtime dynamic object values to JSON data. Create new instance for HttpClient and HttpResponseMessage.
Universal Windows Platform - Complete Solution