SimpleHttpClient 4.1.0
dotnet add package SimpleHttpClient --version 4.1.0
NuGet\Install-Package SimpleHttpClient -Version 4.1.0
<PackageReference Include="SimpleHttpClient" Version="4.1.0" />
paket add SimpleHttpClient --version 4.1.0
#r "nuget: SimpleHttpClient, 4.1.0"
// Install SimpleHttpClient as a Cake Addin
#addin nuget:?package=SimpleHttpClient&version=4.1.0
// Install SimpleHttpClient as a Cake Tool
#tool nuget:?package=SimpleHttpClient&version=4.1.0
SimpleHttpClient
An easy-to-use .NET wrapper for HttpClient. No extension methods, and included interfaces allow for easy unit test mocking, and straightforward properties allows for easier debugging (the response body is available as a string, byte array, and/or a typed object).
Installation
SimpleHttpClient is available on NuGet and can installed through the NuGet Package Manager or by running
nuget install SimpleHttpClient
Basic Usage
SimpleHttpClient is designed to be used with dependency injection in order to avoid pitfalls that come with using an HttpClient
:
In Program.cs
:
// Register SimpleHttpClient with the ServiceCollection
await Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSimpleHttpClient();
})
.Build()
.RunAsync();
Then, in the class that will use the SimpleHttpClient:
public class YourClientClass
{
private readonly SimpleClient client;
// Retrieve an ISimpleHttpClient through dependency injection
public YourClientClass(ISimpleHttpClient client)
{
// Set the host on the retrieved client
client.Host = "https://api.sampleapis.com";
}
public async Task<string> MakeRequest()
{
// Pass the path you want to call into the SimpleRequest constructor
var request = new SimpleRequest("/coffee/hot");
// Call MakeRequest on the client, passing your request, and get your response back
var response = await client.MakeRequest(request);
return response.StringBody;
}
}
You can also call MakeRequest with a type to serialize to that type:
public async Task<SomeResponseObject> MakeRequest()
{
// Pass the path you want to call into the Request constructor
var request = new SimpleRequest("/get");
// Call MakeRequest on the client, passing your request, and get your response back
var response = await client.MakeRequest<SomeResponseObject>(request);
return response.Body;
}
If you're using SimpleHttpClient without dependency injection, you can just create an instance of SimpleClient:
public class YourClientClass
{
private readonly SimpleClient client;
public YourClientClass()
{
// Pass the host you'll be calling into the SimpleClient constructor
client = new SimpleClient("https://api.sampleapis.com");
}
public async Task<string> MakeRequest()
{
// Pass the path you want to call into the SimpleRequest constructor
var request = new SimpleRequest("/coffee/hot");
// Call MakeRequest on the client, passing your request, and get your response back
var response = await client.MakeRequest(request);
return response.StringBody;
}
}
NOTE: Although SimpleClient
implements IDisposable
, it should NOT be created inside a using
block, but instead should be disposed with the class that uses it.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.1.0 | 53 | 4/18/2024 |
4.0.0 | 151 | 4/25/2023 |
3.0.0 | 133 | 4/23/2023 |
2.1.1 | 165 | 4/17/2023 |
2.1.0 | 132 | 4/17/2023 |
2.0.0 | 154 | 4/16/2023 |
1.1.0 | 148 | 4/16/2023 |
1.0.10 | 210 | 2/28/2023 |
1.0.9 | 209 | 2/17/2023 |
1.0.8 | 203 | 2/17/2023 |
1.0.7 | 193 | 2/17/2023 |
1.0.6 | 196 | 2/17/2023 |
1.0.5 | 201 | 2/17/2023 |
1.0.4 | 203 | 2/17/2023 |
1.0.3 | 209 | 2/17/2023 |
1.0.2 | 202 | 2/16/2023 |
1.0.1 | 200 | 2/16/2023 |
1.0.0 | 212 | 2/16/2023 |