All Projects → ziyasal → Httwrap

ziyasal / Httwrap

Licence: MIT License
General purpose, simple but useful HttpClient wrapper for .NET & Xamarin/Mono

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Httwrap

Managed Midi
[Past project] Cross-platform MIDI processing library for mono and .NET (ALSA, CoreMIDI, Android, WinMM and UWP).
Stars: ✭ 130 (+233.33%)
Mutual labels:  xamarin, mono
Uno.playground
Source code for the Uno Gallery apps and Uno Playground (made in Wasm)
Stars: ✭ 184 (+371.79%)
Mutual labels:  xamarin, mono
Megaapiclient
MegaApiClient is a C# .Net library to access http://mega.co.nz / http://mega.nz cloud storage and file hosting service.
Stars: ✭ 151 (+287.18%)
Mutual labels:  xamarin, mono
Socketclusterclientdotnet
C# client for socketcluster framework in node.js
Stars: ✭ 60 (+53.85%)
Mutual labels:  xamarin, mono
Portable-WebDAV-Library
Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETS…
Stars: ✭ 45 (+15.38%)
Mutual labels:  xamarin, mono
Xamarin Forms Gtk Movies Sample
The Movie DB Xamarin.Forms Sample
Stars: ✭ 83 (+112.82%)
Mutual labels:  xamarin, mono
Cppsharp
Tools and libraries to glue C/C++ APIs to high-level languages
Stars: ✭ 2,221 (+5594.87%)
Mutual labels:  xamarin, mono
Embeddinator 4000
Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
Stars: ✭ 735 (+1784.62%)
Mutual labels:  xamarin, mono
uno.toolkit.ui
A set of custom controls for the WinUI and the Uno Platform not offered out of the box by WinUI, such as Card, TabBar, NavigationBar, etc.
Stars: ✭ 45 (+15.38%)
Mutual labels:  xamarin, mono
Standard.licensing
Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and Xamarin products
Stars: ✭ 239 (+512.82%)
Mutual labels:  xamarin, mono
Uno.ch9
Ch9 - Uno Reference Implementation project
Stars: ✭ 45 (+15.38%)
Mutual labels:  xamarin, mono
PCLExt.FileStorage
Portable Storage APIs
Stars: ✭ 35 (-10.26%)
Mutual labels:  xamarin, mono
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+2117.95%)
Mutual labels:  xamarin, mono
Crossplatformdisktest
Windows, macOS and Android storage (HDD, SSD, RAM) speed testing/performance benchmarking app
Stars: ✭ 123 (+215.38%)
Mutual labels:  xamarin, mono
Moonsharp
An interpreter for the Lua language, written entirely in C# for the .NET, Mono, Xamarin and Unity3D platforms, including handy remote debugger facilities.
Stars: ✭ 926 (+2274.36%)
Mutual labels:  xamarin, mono
Forms Gtk Progress
Xamarin.Forms GTK Backend Progress
Stars: ✭ 166 (+325.64%)
Mutual labels:  xamarin, mono
Firesharp
An asynchronous cross-platform .Net library for Firebase
Stars: ✭ 601 (+1441.03%)
Mutual labels:  xamarin, mono
Mathparser.org Mxparser
Math Parser Java Android C# .NET/MONO (.NET Framework, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS) CLS Library - a super easy, rich and flexible mathematical expression parser (expression evaluator, expression provided as plain text / strings) for JAVA and C#. Main features: rich built-in library of operators, constants, math functions, user defined: arguments, functions, recursive functions and general recursion (direct / indirect). Additionally parser provides grammar and internal syntax checking.
Stars: ✭ 624 (+1500%)
Mutual labels:  xamarin, mono
Punchclock
Make sure your asynchronous operations show up to work on time
Stars: ✭ 235 (+502.56%)
Mutual labels:  xamarin, http-client
ably-dotnet
.NET, Xamarin and Mono client library SDK for Ably realtime messaging service
Stars: ✭ 32 (-17.95%)
Mutual labels:  xamarin, mono

Httwrap

General purpose, simple but useful HttpClient wrapper for .NET & Xamarin/Mono

Build statusCoverage Status

How to use

Install

PM> Install-Package Httwrap

Init

  IHttwrapConfiguration configuration = new HttwrapConfiguration("http://localhost:9000/");
  IHttwrapClient _httwrap = new HttwrapClient(configuration);

GET

Basic

IHttwrapResponse<Product> response = await _httwrap.GetAsync<Product>("api/products/1");
Dump(response.Data);
Dump(response.StatusCode);

With QueryString

It supports DataMember and IgnoreDataMember attributes.

/*
public class FilterRequest
{
  [DataMember(Name = "cat")]
  public string Category { get; set; }
  
  public int NumberOfItems { get; set; }
}
*/

var payload = new FilterRequest
{
  Category = "Shoes",
  NumberOfItems = 10
};

//Url: api/test?cat=Shoes&NumberOfItems=10
IHttwrapResponse<List<Product>> response =
                            await _client.GetAsync<List<Product>>("api/test", payload);

Dump(response.Data);
Dump(response.StatusCode);

Serialize response

IHttwrapResponse response = await _httwrap.GetAsync("api/products");
List<Product> values = response.ResultAs<List<Product>>();
Dump(response.StatusCode);

/* ResultAs<T>() extension method uses Newtonsoft.Json serializer by default.  
To use your own serializer set JExtensions.Serializer = new YourCustomSerializerImpl();*/

POST

Product product = new Product{ Name= "Product A", Quantity = 3 };
IHttwrapResponse response = await _httwrap.PostAsync<Product>("api/products",product);
Dump(response.StatusCode);

PUT

Product product = new Product{ Name= "Product A", Quantity = 3 };
IHttwrapResponse response = await _httwrap.PutAsync<Product>("api/products/1",product);
Dump(response.StatusCode);

PATCH

Product product = new Product{ Name= "Product A", Quantity = 3};
IHttwrapResponse response = await _httwrap.PatchAsync<Product>("api/products/1",product);
Dump(response.StatusCode);

DELETE

IHttwrapResponse response = await _httwrap.DeleteAsync("api/products/1");
Dump(response.StatusCode);

Error Handler

IHttwrapResponse<List<Product>> response =
      await _httwrap.GetAsync<List<Product>>("api/products", (statusCode, body) =>
      {
        _logger.Error("Body :{0}, StatusCode :{1}", body, statusCode);
      });

Auth

Basic Credentials

IHttwrapConfiguration configuration = new HttwrapConfiguration("http://localhost:9000/")
{
  Credentials = new BasicAuthCredentials("user", "s3cr3t")
};
IHttwrapClient _httwrap = new HttwrapClient(configuration);

OAuth Credentials

Use existing token

IHttwrapConfiguration configuration = new HttwrapConfiguration("http://localhost:9000/")
{
  Credentials = new OAuthCredentials("token")
};
IHttwrapClient _httwrap = new HttwrapClient(configuration);

Use Username / password to get token from edpoint

IHttwrapConfiguration configuration = new HttwrapConfiguration("http://localhost:9000/")
{
  Credentials = new OAuthCredentials("us3r", "p4ssw0rd", BaseAddress + "/token")
};
IHttwrapClient _httwrap = new HttwrapClient(configuration);

Req/Res Interceptor

public class DummyInterceptor : IHttpInterceptor
{
    private readonly IHttwrapClient _client;

    public void OnRequest(HttpRequestMessage request)
    {
    }

   public void OnResponse(HttpRequestMessage request, HttpResponseMessage response)
   {
      response.StatusCode = HttpStatusCode.Accepted;
   }
}
client.AddInterceptor(new DummyInterceptor());

Bugs

If you encounter a bug, performance issue, or malfunction, please add an Issue with steps on how to reproduce the problem.

TODO

  • Add more tests
  • Add more documentation

License

Code and documentation are available according to the MIT License (see LICENSE).

@ziλasal

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].