EasyHttpsClient 3.0.0
dotnet add package EasyHttpsClient --version 3.0.0
NuGet\Install-Package EasyHttpsClient -Version 3.0.0
<PackageReference Include="EasyHttpsClient" Version="3.0.0" />
<PackageVersion Include="EasyHttpsClient" Version="3.0.0" />
<PackageReference Include="EasyHttpsClient" />
paket add EasyHttpsClient --version 3.0.0
#r "nuget: EasyHttpsClient, 3.0.0"
#:package EasyHttpsClient@3.0.0
#addin nuget:?package=EasyHttpsClient&version=3.0.0
#tool nuget:?package=EasyHttpsClient&version=3.0.0
EasyHttpsClient
v3.0.0
EasyHttpsClient is a simple and easy-to-use HTTP client library for .NET, .NET Core and .NET Framework
It provides an easier syntax for sending GET, POST, PUT, DELETE requests and retrieving response data.
Work In Progress:
Different endpoint requires various requests.
Feel Free to submit issues or pull requests on GitHub aurel192 - EasyHttpsClient repository
Links
GitHub aurel192 - EasyHttpsClient repository
NuGet Package - EasyHttpsClient
Usage
Setting / Adding - Headers, Timeout, Encoding, and more...
using var client = new HttpGetClient();
client.SetUrl("https://example.com");
client.AddToRequestHeaders("Authorization", "Bearer token / ApiKey / etc ...");
client.SetTimeout(10);
client.SetEncoding(Encoding.UTF8);
// The default certificate validation remains enabled.
// Only use this for testing or trusted internal environments:
client.SetServerCertificateCustomValidationCallback(true);
HttpBaseClient also has a constructor that accepts an existing HttpClient.
This is useful when the same HttpClient should be reused. The injected
HttpClient is not disposed by HttpBaseClient.
using var httpClient = new HttpClient();
using var client = new HttpGetClient(httpClient);
SendAsync returns the HttpResponseMessage. Dispose the response after
reading it, and pass it to one of the result-reading methods.
GET:
using var getClient = new HttpGetClient();
getClient.SetUrl("https://localhost:64946/api/TestItems");
using HttpResponseMessage response = await getClient.SendAsync();
// This line will read the result as string
string responseString = await getClient.ReadResultAsStringAsync(response);
// or byte array
byte[] responseByteArray = await getClient.ReadResultAsByteArrayAsync(response);
Console.WriteLine(responseString);
Cancellation can be supplied per request:
using var cancellationTokenSource = new CancellationTokenSource();
using var getClient = new HttpGetClient();
getClient.SetUrl("https://localhost:64946/api/TestItems");
using HttpResponseMessage response =
await getClient.SendAsync(cancellationTokenSource.Token);
POST:
using var postClient = new HttpPostClient();
postClient.SetTimeout(10);
postClient.SetEncoding(Encoding.UTF8);
// POST FormUrlEncodedContent
postClient.SetUrl("https://www.example.com/api/PostKeyValuePairsHere/");
postClient.AddBodyPostData("key1", "value1");
postClient.AddBodyPostData("key2", "value2");
// POST StringContent
var payloadObject = new
{
key = "NEW ITEM KEY",
value = "NEW NEW",
value2 = "BRAND NEW TEST ITEM",
boolean = true,
};
// Note: it can be any serializable object
postClient.SetBodyRequestData(payloadObject);
// Or as a JSON string
// Note: it can be any format (e.g. XML, ...) depending on the endpoint
string payloadJson = @"{""key"": ""NEW ITEM KEY"",""value"": ""NEW NEW"",""value2"": ""BRAND NEW TEST ITEM"",""boolean"": true}";
// postClient.SetBodyRequestJson(payloadJson);
using HttpResponseMessage response = await postClient.SendAsync();
string responseString = await postClient.ReadResultAsStringAsync(response);
PUT
using var putClient = new HttpPutClient();
putClient.SetUrl("https://localhost:64946/api/TestItems/1");
var modifiedObject = new
{
key = "THIS IS NOT THE ORIGINAL",
value = "IT WILL MODIFY",
value2 = "MODIFY THE FIRST ELEMENT",
boolean = true,
};
putClient.SetBodyRequestData(modifiedObject);
using HttpResponseMessage response = await putClient.SendAsync();
string responseString = await putClient.ReadResultAsStringAsync(response);
DELETE
using var deleteClient = new HttpDeleteClient();
deleteClient.SetUrl("https://localhost:64946/api/TestItems/15");
using HttpResponseMessage response = await deleteClient.SendAsync();
string responseString = await deleteClient.ReadResultAsStringAsync(response);
License
This library is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome.
Submit issues or pull requests on GitHub aurel192 - EasyHttpsClient repository
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- System.Net.Http (>= 4.2.0)
- System.Text.Json (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.