:::: MENU ::::

Consuming REST API service in Xamarin.Forms

Web service is one of the important parts of mobile apps development. In this post i am trying to consume RESTFUL web service in Xamarin.Forms.

Requirements (both are Nuget package):

  1. Net.Http- to perform web request and for other services along those lines.
  2. Json- to serializing and deserializing json data.

For this sample I am using REST API service of Nlocate a startup which provides the location of different useful places (Like banks, hospitals etc.) of Nepal.

For sample application I am using Xamarin.Forms (PCL) project template. In this sample app I have not done so much like showing data in listview and other fancy stuffs, all logic are placed under single click event of button.

First I get API link from Nlocate I have my good friend there and i use Json2csharp site to generate required class and property. After I get required class with properties I paste those classes in my .cs file where I am using my logic. Now install nuget packages which I mention above.

Now create a button and in click event I am using this logic for consuming REST service:

Now rebuild the solution, put a break point and run it. If everything is ok you will be able to see output after you click button and here is my output:

And collectively the code looks as:

Thats it. Now you can add more fancy stuffs in your project.


Happy Coding! 🙂

  • I feel this is one of the such a lot important info for
    me. And i am happy studying your article. But wanna statement on some normal things, The site style is wonderful,
    the articles is actually great : D. Excellent job,

  • Heya i’m for the primary time here. I came across this board and I to
    find It really useful & it helped me out a lot. I hope to give something back and aid others such as you helped me.

  • In fact no matter if someone doesn’t know then its up to other users that they will assist, so here it happens.

  • Muhammad Taimoor Janjua


    Nice article. I have a question, How can I consume HTTPS based Rest Service. The service is secured with self signed SSL certificate.

    Thanks in advance,

    Taimoor Janjua