TechHut.Azure.Functions.Projection
8.0.1
See the version list below for details.
dotnet add package TechHut.Azure.Functions.Projection --version 8.0.1
NuGet\Install-Package TechHut.Azure.Functions.Projection -Version 8.0.1
<PackageReference Include="TechHut.Azure.Functions.Projection" Version="8.0.1" />
<PackageVersion Include="TechHut.Azure.Functions.Projection" Version="8.0.1" />
<PackageReference Include="TechHut.Azure.Functions.Projection" />
paket add TechHut.Azure.Functions.Projection --version 8.0.1
#r "nuget: TechHut.Azure.Functions.Projection, 8.0.1"
#:package TechHut.Azure.Functions.Projection@8.0.1
#addin nuget:?package=TechHut.Azure.Functions.Projection&version=8.0.1
#tool nuget:?package=TechHut.Azure.Functions.Projection&version=8.0.1
TechHut.Azure.Functions.Projection
A lightweight library for Azure Functions that enables dynamic JSON response projection. Allow your API clients to specify which fields to include in the response using a $project
specification in the request body, query string, or headers.
Features
- Flexible JSON Projection: Filter and shape JSON responses dynamically.
- Multiple Input Methods: Accepts projection via request body, query string, or headers.
- Seamless Azure Functions Integration: Designed for HTTP-triggered Azure Functions (.NET 8+).
- Easy Middleware Integration: Apply projection globally using middleware—no need to modify individual function code.
Installation
Install via NuGet Package Manager:
dotnet add package TechHut.Azure.Functions.Projection
Or via the NuGet Package Manager UI in Visual Studio.
Usage
1. Register the Middleware
Add the projection middleware in your Azure Functions application's startup code (typically in Program.cs
):
using TechHut.Azure.Functions.Projection.Extensions;
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication()
.AddProjectionMiddleware();
builder.Build().Run();
Note:
If you need to allow synchronous IO (for certain scenarios), you can configure Kestrel as shown in the example project.
2. Write Your Function as Usual
You do not need to manually apply projection logic in your function code. Simply return your JSON response as usual:
[Function("Customers")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
var jsonContent = await File.ReadAllTextAsync(@".\customers.json", Encoding.UTF8);
response.Headers.Add("Content-Type", "application/json");
await response.WriteStringAsync(jsonContent);
return response;
}
The middleware will automatically intercept and apply the projection to the response if the client specifies one.
3. Client-Side Usage
Clients can specify the projection in one of three ways:
- Request Body (for
application/json
):
json
{ "$project": { "field1": {}, "field2": {} } }
-
- Query String:
?$project={"field1":{},"field2":{}}
-
- Header:
$project: {"field1":{},"field2":{}}
Example
Request:
POST /api/Customers
Content-Type: application/json
{
"$project":
{
"name": null,
"age": null,
"address":
[
{
"street": null,
"postcode": null
}
]
}
}
Response:
json
{ "name": "Alice", "age": 30 }
Requirements
- .NET 8 or later
- Azure Functions v4 or later
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Azure.Functions.Worker (>= 2.0.0)
- Microsoft.Azure.Functions.Worker.Sdk (>= 2.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## [8.0.1] - 2025-06-09
### Removed
- Removed dependency on `Microsoft.AspNetCore.Http.Features`. This reduces package size and eliminates unnecessary transitive dependencies.
No breaking changes are expected for consumers.