Xamabrouk.RestHelper

Provides a full and clean solution to POST, GET,PUT or DELETE data to server using a Rest API..

Introduction

Most of developer are using Web APIs when creating Mobile, Desktop or Web Apps. Every Web API provides a nuber of methodes to be called in the client side : POST, GET, PUT, DELETE.

In oder to help developers to implement a simple an clean client code, i wrote my Nuget Package https://www.nuget.org/packages/Xamabrouk.RestHelper/.

Let’s start coding !

In order to test and discover the functionalities of our Package we will use the public Rest API :
https://www.predic8.de/rest-api-public-sample.htm . You can find more details in the Swagger-UI.

First of all, install the Nuget Package in your project.

We will use the Customer API witch returns a json result in this form :

{
  "meta": {
    "count": 22,
    "limit": 10,
    "page": 2,
    "previous_url": "/shop/products/?page=1&limit=10",
    "next_url": "/shop/products/?page=3&limit=10"
  },
  "customers": [
    {
      "firstname": "Susan",
      "lastname": "Tanner",
      "customer_url": "/shop/customer/642"
    }
  ]
}

We need now to create our ViewModel :

Note : Your Model should implement the IXMModel interface.

 public class Customer : IXMModel<long>

Now for the service you just need to inherit from the
XMBaseDataService and set your Model in the generic type and the type of the id of your Model.

public class CustomersService : XMBaseDataService<Customer, long>

In our example it’s like :

It’s too easy now to load data, just call :

CustomersService customersService = new CustomersService();
var customers = customersService.GetAllItems<VMCustomer>();

You can also use async methodes like :

var customers = await customersService.GetAllItemsAsync<VMCustomer>();

Note : All methodes can be called asynchronous and also can be overridden!

See the simple project here and enjoy! : https://github.com/MabroukENG/XM.RestHelper.Simple.

0Shares

15 Replies to “Xamabrouk.RestHelper”

  1. Magnificent beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog site?
    The account helped me a acceptable deal. I had been a little bit acquainted of this your
    broadcast offered bright clear idea

  2. Excellent post. Keep writing such kind of info
    on your blog. Im really impressed by it.
    Hello there, You have done an incredible job. I will certainly digg it and in my opinion suggest to my friends.
    I am confident they’ll be benefited from this web site.

  3. Hey there! Do you know if they make any plugins to assist
    with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not
    seeing very good gains. If you know of any please
    share. Cheers!

  4. I’ve read a few excellent stuff here. Certainly worth bookmarking for revisiting.
    I wonder how much effort you set to make this kind of wonderful informative
    web site.

  5. Fantastic beat ! I wish to apprentice whilst you amend your web site,
    how can i subscribe for a blog website? The account helped me a applicable deal.
    I were a little bit familiar of this your
    broadcast provided vibrant transparent concept

  6. What’s up i am kavin, its my first time to commenting anywhere, when i
    read this post i thought i could also create comment due to this good
    paragraph.

    Feel free to visit my website: buy CBD

  7. Having read this I believed it was very
    informative. I appreciate you spending some time and
    effort to put this article together. I once again find myself personally spending a lot of time
    both reading and commenting. But so what, it was still worth it!

Leave a Reply

Your email address will not be published.