Functions.Worker.Extensions.HttpApi
3.0.0-preview1
This is a prerelease version of Functions.Worker.Extensions.HttpApi.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Functions.Worker.Extensions.HttpApi --version 3.0.0-preview1
NuGet\Install-Package Functions.Worker.Extensions.HttpApi -Version 3.0.0-preview1
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="Functions.Worker.Extensions.HttpApi" Version="3.0.0-preview1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Functions.Worker.Extensions.HttpApi --version 3.0.0-preview1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Functions.Worker.Extensions.HttpApi, 3.0.0-preview1"
#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 Functions.Worker.Extensions.HttpApi as a Cake Addin #addin nuget:?package=Functions.Worker.Extensions.HttpApi&version=3.0.0-preview1&prerelease // Install Functions.Worker.Extensions.HttpApi as a Cake Tool #tool nuget:?package=Functions.Worker.Extensions.HttpApi&version=3.0.0-preview1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HTTP API Extensions for Azure Functions
Features
- Better route precedence
- Model validation
- ASP.NET Core like helpers
- Support URL generation
- Handle static files
- Simple reverse proxy
- Streamlined SPA / SSG hosting
Installation
Install-Package WebJobs.Extensions.HttpApi
dotnet add package WebJobs.Extensions.HttpApi
// Inherits from `HttpFunctionBase` class
public class Function1 : HttpFunctionBase
{
public Function1(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function1")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
ILogger log)
{
return Ok($"Hello, {req.Query["name"]}");
}
}
Examples
Model validation
public class Function1 : HttpFunctionBase
{
public Function1(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function1")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "post")]
SampleModel model,
ILogger log)
{
if (!TryValidateModel(model))
{
return BadRequest(ModelState);
}
return Ok(model);
}
}
public class SampleModel
{
[Required]
public string Name { get; set; }
public string[] Array { get; set; }
[Range(100, 10000)]
public int Price { get; set; }
}
ASP.NET Core like helpers
public class Function2 : HttpFunctionBase
{
public Function2(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function2")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get")]
HttpRequest req,
ILogger log)
{
Response.Headers.Add("Cache-Control", "no-cache");
return Ok($"Now: {DateTime.Now}");
}
}
Support URL generation
public class Function3 : HttpFunctionBase
{
public Function3(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function3")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "route/{id}")]
HttpRequest req,
string id,
ILogger log)
{
return CreatedAtFunction("Function3", new { id = "kazuakix" }, null);
}
}
Handle static files
public class Function1 : HttpFunctionBase
{
public Function1(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function1")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
ILogger log)
{
return File("sample.html");
}
}
Simple reverse proxy
public class Function1 : HttpFunctionBase
{
public Function1(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function1")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*path}"})] HttpRequest req,
ILogger log)
{
return Proxy("https://example.com/{path}");
}
}
Streamlined SPA / SSG hosting
public class Function1 : HttpFunctionBase
{
public Function1(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
[FunctionName("Function1")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*path}"})] HttpRequest req,
ILogger log)
{
#if USE_REMOTE
return RemoteStaticApp("https://example.com", fallbackExclude: $"^/_nuxt/.*");
#else
return LocalStaticApp(fallbackPath: "404.html", fallbackExclude: $"^/_nuxt/.*");
#endif
}
}
License
This project is licensed under the MIT 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
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 |
---|---|---|
3.0.0 | 127 | 11/18/2024 |
3.0.0-preview1 | 63 | 8/4/2024 |