An Introduction to EcSolvo.RestHelper

This post intends to act as an introductory guide on the EcSolvo.RestHelper Nuget. It takes you through the Main Methods that you would be using in your routine tasks.

RestHelper Constructor and ExecuteAsync

The RestHelper Constructor and ExecuteAsync Method is the heart of RestHelper Library. It is build on ‘Pit of Success’ philosophy, removing possible erroneous steps by the consuming Developer.
The RestHelper Constructor takes a single Parameter, which is the base address of your API.The ExecuteAsync is an Asynchronous Method which take in two Parameters,
b) Resource (URL to the exact API Resource)

For GET Request

For Handling URI Parameters, the EcSolvo.RestHelper Library exposes a method called ‘AddURLParameters’, which helps to add parameters to the QueryString dictionary.

private string _BaseAddress = "http://localhost:8888/";
var resourceURL = "api/user/SingleParamStringResponse";
var restHelper = new EcSolvo.RestHelper(_BaseAddress);
string ParameterKey = "VariableStr";
string ParameterValue = "DummyString";
restHelper.AddURLParameters(ParameterKey, ParameterValue);
var result = await restHelper.ExecuteAsync(HttpMethod.Get, resourceURL);

The library works even if the parameter passed is a Complex Parameter (Controller uses FromUri Attribute).

For POST Request

For Handling OnBody Parameter in POST Request, the library exposes a method called ‘AssignMessageBodyParameter’.

var result = await restHelper.ExecuteAsync(HttpMethod.Post, resourceURL);

If the POST Request have additional URI Parameters, it can use the ‘AddURLParameters’ Method to add it to the dictionary.

Store User Credentials using Xamarin.Auth in Xamarin.Forms

If you are working on Mobile Apps, it won’t be long before you end up with a scenario to store User Account objects locally so that the user needn’t go through the pain of authenticating himself all over again, every time he logs in. One of the easiest way to do is via the cross platform Xamarin.Auth SDK  (Click here for Details).

The SDK uses Keychain Services for iOS and KeyStore Class for Android for its implementation.

Like always with any platform specific implementation, we would be using DepedencyService to define the platform specific behavior, in this case, the SDK uses KeyChain Services for iOS and KeyStore for Droid. Let’s go ahead and declare the Interface first.

public interface IAuthService
 void SaveCredentials(string UserName, string Password);
 string UserName { get; }
 string Password { get; }

The next step is to go ahead and implement the interface in the required platform. We will be covering Android Platform in this example.

class AuthService : IAuthService
 public string Password
 var account = AccountStore.Create(Application.Context).FindAccountsForService(Application.Context.ApplicationInfo.Name).FirstOrDefault();
 return (account != null) ? account.Properties["Password"] : null;
 public string UserName
 var account = AccountStore.Create(Application.Context).FindAccountsForService(Application.Context.ApplicationInfo.Name).FirstOrDefault();
 return (account != null) ? account.Username : null;
 public void SaveCredentials(string UserName, string Password)
 if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(Password))
 Account account = new Account
 Username = UserName
 account.Properties.Add("Password", Password);
 AccountStore.Create(Application.Context).Save(account, Application.Context.ApplicationInfo.Name);

Do not forget to register your implementation with DependencyService by decorating the namespace with Dependency Attribute.

[assembly: Xamarin.Forms.Dependency(typeof(AuthService))]

That’s it, now you can go ahead and use it in your class in the Xamarin.Form PCL.

var AuthService = DependencyService.Get<IAuthService>();
AuthService.SaveCredentials(EmailID, Password);

EcSolvo.RestHelper Nuget

Recently I have started working on a Nuget Package for providing a is a sleek and simple Wrapper library for providing simple access to Rest API, by hiding away the complexities of HTTPClient Class.Named EcSolvo.RestHelper it is particularly designed to work along with Xamarin PCL Projects

You can follow and contribute to the Nuget in Github : Link to GitHub Repository

Follow updates on Nuget : Link To Nuget