Tizzani.AzureFunctionsWorkerHttpExtensions 1.0.0-preview2

This is a prerelease version of Tizzani.AzureFunctionsWorkerHttpExtensions.
dotnet add package Tizzani.AzureFunctionsWorkerHttpExtensions --version 1.0.0-preview2                
NuGet\Install-Package Tizzani.AzureFunctionsWorkerHttpExtensions -Version 1.0.0-preview2                
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="Tizzani.AzureFunctionsWorkerHttpExtensions" Version="1.0.0-preview2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tizzani.AzureFunctionsWorkerHttpExtensions --version 1.0.0-preview2                
#r "nuget: Tizzani.AzureFunctionsWorkerHttpExtensions, 1.0.0-preview2"                
#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.
// Install Tizzani.AzureFunctionsWorkerHttpExtensions as a Cake Addin
#addin nuget:?package=Tizzani.AzureFunctionsWorkerHttpExtensions&version=1.0.0-preview2&prerelease

// Install Tizzani.AzureFunctionsWorkerHttpExtensions as a Cake Tool
#tool nuget:?package=Tizzani.AzureFunctionsWorkerHttpExtensions&version=1.0.0-preview2&prerelease                

AzureFunctionsWorkerHttpExtensions

This package adds support for binding query parameters in Azure Functions HTTP Triggers.

dotnet add package Tizzani.AzureFunctionsWorkerHttpExtensions

Usage

For more examples, check here.

// Bind directly to primitive types:
[Function(nameof(Example1))]
public HttpResponseData Example1(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
    [BindQuery] string? name,
    [BindQuery] int[]? luckyNumbers)
{
    var response = req.CreateResponse(HttpStatusCode.OK);
    response.WriteString($"Hello, {(name ?? "user")}! ");

    if (luckyNumbers == null || luckyNumbers.Length == 0)
    {
        response.WriteString("You do not have any lucky numbers!");
    }
    else
    {
        response.WriteString($"Your lucky numbers are: {string.Join(", ", luckyNumbers)}");
    }
    return response;
}

// Or bind to POCO:
[Function(nameof(Example2))]
public HttpResponseData Example2(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
    [BindQuery] Poco? poco)
{
    var response = req.CreateResponse(HttpStatusCode.OK);
    response.WriteString($"Hello, {poco?.Name ?? "user"}! ");

    if (poco?.LuckyNumbers == null)
    {
        response.WriteString("You do not have any lucky numbers!");
    }
    else
    {
        response.WriteString($"Your lucky numbers are: {string.Join(", ", poco.LuckyNumbers)}");
    }

    return response;
}

// Or do both!:
[Function(nameof(PocoAndPrimitiveCombo))]
public async Task<HttpResponseData> PocoAndPrimitiveCombo(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
    [BindQuery] Person? person,
    [BindQuery] string? description)
{
    var response = req.CreateResponse(System.Net.HttpStatusCode.OK);

    await response.WriteAsJsonAsync(new 
    {
        person?.Name,
        person?.Age,
        description 
    });
    
    return response;
}

public record Person(string Name, int Age);
public record Poco(string Name, int[] LuckyNumbers);
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. 
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
1.0.0-preview2 102 7/28/2024
1.0.0-preview1 51 7/28/2024