Skip to content
Cross Platform REST Client for all C# platforms
C# Other
  1. C# 99.7%
  2. Other 0.3%
Branch: master
Clone or download
Latest commit d3cfaf4 Aug 19, 2019

README.md

Cross Platform REST Client for all C# platforms

This most simple Task-based Async, strongly typed, cross-platform C# REST Client.

In Browser (Wasm) Support with Uno Platform - New!

RestClient.Net can now run inside the browser via WebAssembly. To see a sample:

  • Clone the repo
  • Make sure you've got .NET Core 3.0 installed
  • Open the solution RestClient.Net.Samples.sln in Visual Studio 2017
  • Switch to debug
  • Unload or remove any projects whose frameworks are not installed (e.g. Android/iOS)
  • Wait for NuGet packages to be restored
  • Ensure the project RestClient.Net.Samples.Uno.Wasm is built
  • Run the project RestClient.Net.Samples.Uno.Wasm
  • Click "Get My Repos" to get my public repos, or enter your own username/password for your private repos
  • This is the code. It's shared across Wasm and UWP
  • If you run the RestClient.Net.Samples.Uno.UWP project, you will see that the app is almost identicle to the one in the browser
  • Log any issues in the issues section please!

Comparison

Library .NET Framework Get 15x .NET Core Get 15x .NET Core Patch 15x
RestClient.Net 5831.1539ms 5724.9672ms 7569.8823ms
RestSharp 7010.3713ms 12391.7717ms 13420.5781ms

Note: benchmarks are biased! Please submit a pull request to fix these benchmarks and make them objective.

Features

  • Open Source. (MIT License)
  • Markup language agnostic. (Supports JSON, Binary, SOAP and other markup languages with dependency injection)
  • Use strong types with REST.
  • Supports Android, iOS, Windows 10, .NET Framework, .NET Core (.NET Standard 2.0) .
  • Incredibly simple (All source code less than 200 lines)
  • Async friendly (uses async, await keywords).
  • Only one .NET Standard library for all platforms

Quick Start & Samples

Samples for all platforms in this Git repo:

https://github.com/MelbourneDeveloper/RestClient.Net.git

NuGet: Install-Package RestClient.NET

Blog: https://christianfindlay.wordpress.com/

Get

var countryCodeClient = new RestClientDotNet.RestClient(new NewtonsoftSerializationAdapter(), new Uri("http://services.groupkt.com/country/get/all"));
var countryData = await countryCodeClient.GetAsync<groupktResult<CountriesResult>>();

Put

Post is basically the same

private void GetBitBucketClient(string password, bool isGet)
{
    var url = "https://api.bitbucket.org/2.0/repositories/" + UsernameBox.Text;
    _BitbucketClient = new RestClient(new NewtonsoftSerializationAdapter(), new Uri(url));

    if (!string.IsNullOrEmpty(password))
    {
        var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(UsernameBox.Text + ":" + password));
        _BitbucketClient.Headers.Add("Authorization", "Basic " + credentials);
    }
}
        
private async Task OnSavedClicked()
{
    ToggleBusy(true);

    try
    {
        var selectedRepo = ReposBox.SelectedItem as Repository;
        if (selectedRepo == null)
        {
            return;
        }

        //Ensure the client is ready to go
        GetBitBucketClient(GetPassword(), false);

        //var repoSlug = selectedRepo.full_name.Split('/')[1];
        var requestUri = $"https://api.bitbucket.org/2.0/repositories/{UsernameBox.Text}/{selectedRepo.full_name.Split('/')[1]}";

        //Post the change
        var retVal = await _BitbucketClient.PutAsync<Repository, Repository>(selectedRepo, requestUri);

        await DisplayAlert("Saved", "Your repo was updated.");
    }
    catch (Exception ex)
    {
        await HandleException(ex);
    }

    ToggleBusy(false);
}            

Patch

var restClient = new RestClient(new NewtonsoftSerializationAdapter(), new Uri("https://jsonplaceholder.typicode.com"));
var userPost = await restClient.PatchAsync<UserPost, UserPost>(new UserPost { title = "Moops" }, "/posts/1");

Delete

var restClient = new RestClient(new NewtonsoftSerializationAdapter(), new Uri("https://jsonplaceholder.typicode.com"));
await restClient.DeleteAsync("/posts/1");

Hardfolio runs on RestClient.Net

Windows Store https://www.microsoft.com/en-au/p/hardfolio/9p8xx70n5d2j

Google Play https://play.google.com/store/apps/details?id=com.Hardfolio

Donate

Bitcoin: 33LrG1p81kdzNUHoCnsYGj6EHRprTKWu3U

Ethereum: 0x7ba0ea9975ac0efb5319886a287dcf5eecd3038e

Litecoin: MVAbLaNPq7meGXvZMU4TwypUsDEuU6stpY

Contribution

You can’t perform that action at this time.