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.
- Host: GitHub
- URL: https://github.com/stefh/ihttpclient
- Owner: StefH
- License: mit
- Created: 2023-12-08T12:06:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T11:54:10.000Z (about 2 years ago)
- Last Synced: 2024-05-22T22:20:31.506Z (about 2 years ago)
- Language: C#
- Size: 41 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
[](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 });
```