Quantcast
Channel: February 2018 – XamGirl
Viewing all articles
Browse latest Browse all 3

Consuming a RESTful Web Service in Xamarin Forms using Refit (Part 3)

$
0
0

In the second part of this series of articles, we talked about how to structure your project using Refit.

In this article, we are going to talk about how to structure your project to consume multiple APIs.

Let’s start understanding the issue

In the previous article we were consuming the MakeUp API, in this sample beside this API, we are going to consume the Reddit API to show a TimeLine.

The endpoint we are going to use is :

GET/ http://www.reddit.com/r/subreddit/new.json?sort=top&limit=20 which will return the latest 20 Reddit posts.

At this moment maybe you could think that we have to rewrite all the classes/methods we did before for to adapt it to this new API, but not, actually we can reuse all we did.

Expected result:

Let’s do it step by step

1-In the Config file add the new API Url

2-Create a new Refit interface API class and add the endpoint

3-In the IAPiManager class, add the new method definition

4-In the APiManager class, receive the new API and also implement the GetNews method

5-In the BaseViewModel, create an instance of the RedditApi and pass it to the APIManager

6-Call the request in the ViewModel

And that’s all!

You can check the full source code here:

https://github.com/CrossGeeks/RefitXamarinFormsSample/tree/Part3-ConsumingMultipleApis

Happy coding! 🙂

 

The post Consuming a RESTful Web Service in Xamarin Forms using Refit (Part 3) appeared first on XamGirl.


Viewing all articles
Browse latest Browse all 3

Trending Articles