TechHut.Azure.Functions.Projection 8.0.1

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TechHut.Azure.Functions.Projection" Version="8.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TechHut.Azure.Functions.Projection" Version="8.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TechHut.Azure.Functions.Projection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TechHut.Azure.Functions.Projection --version 8.0.1
                    
#r "nuget: TechHut.Azure.Functions.Projection, 8.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TechHut.Azure.Functions.Projection@8.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TechHut.Azure.Functions.Projection&version=8.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TechHut.Azure.Functions.Projection&version=8.0.1
                    
Install as a Cake Tool

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

LICENSE

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
8.0.2 223 6/9/2025
8.0.1 222 6/9/2025
8.0.0 220 6/9/2025

## [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.