CommonNetFuncs.Web.Requests
4.0.43
See the version list below for details.
dotnet add package CommonNetFuncs.Web.Requests --version 4.0.43
NuGet\Install-Package CommonNetFuncs.Web.Requests -Version 4.0.43
<PackageReference Include="CommonNetFuncs.Web.Requests" Version="4.0.43" />
<PackageVersion Include="CommonNetFuncs.Web.Requests" Version="4.0.43" />
<PackageReference Include="CommonNetFuncs.Web.Requests" />
paket add CommonNetFuncs.Web.Requests --version 4.0.43
#r "nuget: CommonNetFuncs.Web.Requests, 4.0.43"
#:package CommonNetFuncs.Web.Requests@4.0.43
#addin nuget:?package=CommonNetFuncs.Web.Requests&version=4.0.43
#tool nuget:?package=CommonNetFuncs.Web.Requests&version=4.0.43
CommonNetFuncs.Web.Requests
This lightweight project contains helper methods for several common functions required by applications.
Contents
RestHelpers
A generic HTTP client wrapper that sends typed REST requests and deserializes responses. Built on a long-lived SocketsHttpHandler-backed HttpClient with configurable keep-alive, per-request bearer tokens, custom headers, timeouts, and optional MessagePack serialization. All requests are made via a RequestOptions<TBody> configuration object so callers never construct HttpRequestMessage by hand.
RestHelpers Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
RestRequest
Sends a request and returns a deserialized response, or null on failure.
using CommonNetFuncs.Web.Requests.Rest;
RestHelpers rest = new();
MyResponse? response = await rest.RestRequest<MyResponse, MyBody>(
new RequestOptions<MyBody>
{
Url = "https://api.example.com/items",
HttpMethod = HttpMethod.Post,
BodyObject = new MyBody { Name = "Widget" },
BearerToken = "my-token",
Timeout = 30, // seconds
}
);
StreamingRestRequest
Streams a newline-delimited JSON (NDJSON) response as an IAsyncEnumerable<T>, useful for large or server-sent data sets.
await foreach (MyItem? item in rest.StreamingRestRequest<MyItem, object?>(
new RequestOptions<object?> { Url = "https://api.example.com/stream", HttpMethod = HttpMethod.Get }))
{
if (item is not null) Process(item);
}
RestRequestObject
Returns a RestObject<TResponse> wrapping both the deserialized response and the raw HttpResponseMessage, giving access to status codes and headers.
RestObject<MyResponse> result = await rest.RestRequestObject<MyResponse, object?>(
new RequestOptions<object?> { Url = "https://api.example.com/items/1", HttpMethod = HttpMethod.Get }
);
if (result.Response?.IsSuccessStatusCode == true)
{
MyResponse? data = result.Result;
}
</details>
PatchCreator
Creates a Newtonsoft.Json JsonPatchDocument by diffing two objects of the same type. Compares property values and generates add, remove, and replace operations for every changed field, including nested objects.
PatchCreator Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
CreatePatch
using CommonNetFuncs.Web.Requests;
using Microsoft.AspNetCore.JsonPatch;
MyEntity original = await GetFromDb(id);
MyEntity modified = original with { Name = "New Name", Price = 9.99m };
JsonPatchDocument patch = PatchCreator.CreatePatch(original, modified);
// patch.Operations => [ { op: "replace", path: "/Name", value: "New Name" }, { op: "replace", path: "/Price", value: 9.99 } ]
// Send via REST
await rest.RestRequest<MyEntity, HttpContent>(
new RequestOptions<HttpContent>
{
Url = $"https://api.example.com/items/{id}",
HttpMethod = HttpMethod.Patch,
PatchDocument = patch.ToStringContent(),
}
);
</details>
DistributedCacheExtensions
Generic IDistributedCache extension methods for storing and retrieving strongly-typed objects serialized with System.Text.Json.
DistributedCacheExtensions Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
using CommonNetFuncs.Web.Requests;
// Store
await cache.SetAsync("user:42", myUser, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
});
// Retrieve synchronously
if (cache.TryGetValue("user:42", out MyUser? user))
{
// cache hit
}
// Retrieve asynchronously
MyUser? user = await cache.TryGetValueAsync<MyUser>("user:42");
</details>
JsonPatchFormatter
Provides a pre-configured NewtonsoftJsonPatchInputFormatter for use with MVC controller-based APIs that accept JsonPatchDocument<T> as a request body. Insert it as the first input formatter so Newtonsoft.Json handles JSON Patch deserialization while the rest of the pipeline uses System.Text.Json.
JsonPatchFormatter Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
using CommonNetFuncs.Web.Requests;
builder.Services.AddControllers(options =>
{
options.InputFormatters.Insert(0, JsonPatchFormatter.JsonPatchInputFormatter());
});
</details>
Installation
Install via NuGet:
dotnet add package CommonNetFuncs.Web.Requests
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- CommonNetFuncs.Compression (>= 4.0.43)
- CommonNetFuncs.Core (>= 4.0.43)
- CommonNetFuncs.Web.Common (>= 4.0.43)
- MemoryPack (>= 1.21.4)
- MessagePack (>= 3.1.4)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.8)
- Microsoft.AspNetCore.JsonPatch (>= 10.0.8)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 10.0.8)
- System.Linq.Async (>= 7.0.1)
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.0.56 | 55 | 6/2/2026 |
| 4.0.53 | 98 | 5/28/2026 |
| 4.0.49 | 97 | 5/24/2026 |
| 4.0.48 | 96 | 5/24/2026 |
| 4.0.43 | 104 | 5/14/2026 |
| 4.0.40 | 107 | 5/10/2026 |
| 4.0.39 | 115 | 5/10/2026 |
| 4.0.37 | 104 | 5/9/2026 |
| 4.0.36 | 102 | 5/8/2026 |
| 4.0.33 | 124 | 4/23/2026 |
| 4.0.31 | 106 | 4/21/2026 |
| 4.0.30 | 106 | 4/23/2026 |
| 4.0.29 | 105 | 4/20/2026 |
| 4.0.28 | 105 | 4/19/2026 |
| 4.0.27 | 118 | 4/15/2026 |
| 4.0.25 | 118 | 4/3/2026 |
| 4.0.23 | 111 | 3/30/2026 |
| 3.8.44 | 116 | 3/13/2026 |