HttpHandlerAttribute class
Marks the method that handles every HTTP request in an application written without ASP.NET.
[AttributeUsage(AttributeTargets.Method)]
public sealed class HttpHandlerAttribute : Attribute
Public Members
| name | description |
|---|---|
| HttpHandlerAttribute() | The default constructor. |
Remarks
Use it when one method is all the application needs. The project uses the Isoplane.Sdk project SDK and has no Program.cs; dotnet new isoplane-handler creates one, with tests. An application that wants routing, middleware or dependency injection is an ASP.NET application instead, and starts from IsoplaneHosting.CreateBuilder. Handle requests without ASP.NET walks through a complete project.
The method is static, returns Task<Response> and takes a Request. It can have any name. It may take a StreamingRequest in place of the Request, to read a large body as it arrives. An application has exactly one such method. The build reports an error on a method that breaks these rules, on a second marked method, and on a project that has none.
Isoplane scales instances with traffic, up to the application’s instance limit, and may discard an instance between requests. Await work the response depends on before returning. Remaining work transfers to the instance’s bounded background allowance and may never finish. Keep durable state in a database or another external service.
Examples
using Isoplane;
public static class Handler
{
[HttpHandler]
public static Task<Response> HandleAsync(Request request) =>
Task.FromResult(request.Path == "/"
? Response.Text("Hello from Isoplane!")
: Response.Text("Not found", 404));
}
See Also
- class TemplateInitializerAttribute
- class InstanceStartAttribute
- namespace Isoplane