An open API service indexing awesome lists of open source software.

https://github.com/stefh/ihttpclient

This project uses source generation to generate an IHttpClient interface and HttpClientProxy from the HttpClient to make it injectable and unit-testable.
https://github.com/stefh/ihttpclient

Last synced: about 1 year ago
JSON representation

This project uses source generation to generate an IHttpClient interface and HttpClientProxy from the HttpClient to make it injectable and unit-testable.

Awesome Lists containing this project

README

          

## ⏩ Moved
This project is now archived and moved to [StefH/Interfaces](https://github.com/StefH/Interfaces).

---

## Info
This project uses source generation to generate an `IHttpClient` interface and `HttpClientProxy` from the `HttpClient` to make it injectable and unit-testable.

All the methods and properties from the `HttpClient` are replicated to `IHttpClient`.

## NuGet
[![NuGet Badge](https://img.shields.io/nuget/v/IHttpClient)](https://www.nuget.org/packages/IHttpClient)

## Usage
``` c#
HttpClient httpClient = new HttpClient();
IHttpClient httpClientProxy = new HttpClientProxy(httpClient);

var result = await httpClientProxy.GetAsync("https://www.google.nl");
var todo = await httpClientProxy.GetFromJsonAsync("https://jsonplaceholder.typicode.com/todos/1");
var postResult = await httpClientProxy.PostAsJsonAsync("https://jsonplaceholder.typicode.com/todos", new Todo { Id = 123 });
var patchResult = await httpClientProxy.PatchAsJsonAsync("https://jsonplaceholder.typicode.com/todos/1", new Todo { Id = 400 });
var putResult = await httpClientProxy.PutAsJsonAsync("https://jsonplaceholder.typicode.com/todos/1", new Todo { Id = 444 });
```