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

178 Replies to “Xamabrouk.RestHelper”

  1. Pingback: Mktg Thailand
  2. Hmm it looks like your website ate my first comment (it was extremely long)
    so I guess I’ll just sum it up what I had written and say, I’m thoroughly
    enjoying your blog. I too am an aspiring blog blogger but I’m still new to everything.
    Do you have any recommendations for inexperienced
    blog writers? I’d genuinely appreciate it.

  3. I think this is one of the most important info for
    me. And i’m glad reading your article. But want to remark on some general things, The website
    style is perfect, the articles is really great : D. Good job,
    cheers

  4. Greetings from California! I’m bored to death at work so I decided to check out your website on my iphone during lunch break.
    I enjoy the info you provide here and can’t wait to
    take a look when I get home. I’m amazed at how fast your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyhow, good blog!

  5. Woah! I’m really loving the template/theme of this
    site. It’s simple, yet effective. A lot of times it’s challenging to get
    that “perfect balance” between usability and appearance.
    I must say that you’ve done a awesome job with this. Additionally,
    the blog loads very fast for me on Safari. Outstanding Blog!

  6. Pingback: cannabis4homes.com
  7. Pingback: matryoshka
  8. Pingback: dildo with balls
  9. Pingback: hectic radio
  10. Pingback: gamdom
  11. Pingback: Semilac uk
  12. First off I would like to say fantastic blog! I had a quick question that I’d like to ask if you don’t mind. I was curious to find out how you center yourself and clear your head before writing. I’ve had a tough time clearing my mind in getting my ideas out there. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes tend to be lost simply just trying to figure out how to begin. Any recommendations or tips? Thanks!|

Leave a Reply

Your email address will not be published.