Skip to content

HTTP Context

For reading request headers, accessing the authenticated user, or inspecting route values beyond what TRequest covers, inject EndpointContext via the constructor. Avoid injecting it when typed request/response is sufficient.

public class FindByIdEndpoint : IEndpoint<FindByIdRequest, Response<UserResponse>>
{
private readonly EndpointContext _context;
public FindByIdEndpoint(EndpointContext context) => _context = context;
public void Configure(IEndpointConfiguration config)
{
config.Get("/users/{id}").Summary("Get a user by ID");
}
public Task<Response<UserResponse>> HandleAsync(
FindByIdRequest request,
CancellationToken cancel)
{
var language = _context.RequestHeaders["Accept-Language"].FirstOrDefault() ?? "en";
// ...
}
}
MemberTypeDescription
RequestHeadersIHeaderDictionaryIncoming request headers
UserClaimsPrincipalThe authenticated user
QueryIQueryCollectionRaw query string values
GetRouteValue(key)string?A single route parameter by name
RawResponseHttpResponseEscape hatch for writing directly to the response stream

RawResponse is intended for cases that Response<TBody> and extension packages cannot cover. For CSV output, the CSV Helper extension is the preferred approach.