Table of Contents

Class HttpResponseOptionsBuilder<TDomain>

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Fluent options builder for ToHttpResponse<T>(Result<T>, Action<HttpResponseOptionsBuilder<T>>?). Selectors run against the TDomain value (not the projected response body).

public sealed class HttpResponseOptionsBuilder<TDomain>

Type Parameters

TDomain

The domain value type from Result<TDomain>.

Inheritance
HttpResponseOptionsBuilder<TDomain>
Inherited Members
Extension Methods

Methods

Created(Func<TDomain, string>)

Returns 201 Created with a Location header derived from the domain value.

public HttpResponseOptionsBuilder<TDomain> Created(Func<TDomain, string> selector)

Parameters

selector Func<TDomain, string>

Returns

HttpResponseOptionsBuilder<TDomain>

Created(string)

Returns 201 Created with a literal Location header (e.g. /orders/123).

public HttpResponseOptionsBuilder<TDomain> Created(string locationLiteral)

Parameters

locationLiteral string

Returns

HttpResponseOptionsBuilder<TDomain>

CreatedAtAction(string, Func<TDomain, RouteValueDictionary>, string?)

Returns 201 Created with a Location header generated via LinkGenerator.GetUriByAction (resolved from HttpContext.RequestServices at execute time). Equivalent to MVC's CreatedAtAction.

[RequiresUnreferencedCode("CreatedAtAction relies on MVC's ControllerLinkGeneratorExtensions which is not trim-safe. Use CreatedAtRoute with a named route for AOT/trim scenarios.")]
[RequiresDynamicCode("CreatedAtAction relies on MVC's ControllerLinkGeneratorExtensions which is not AOT-safe. Use CreatedAtRoute with a named route for AOT scenarios.")]
public HttpResponseOptionsBuilder<TDomain> CreatedAtAction(string actionName, Func<TDomain, RouteValueDictionary> routeValues, string? controllerName = null)

Parameters

actionName string

The action method name.

routeValues Func<TDomain, RouteValueDictionary>

A function that returns a RouteValueDictionary for the new resource. Pass a RouteValueDictionary rather than an anonymous type to remain AOT-compatible.

controllerName string

Optional controller name (defaults to the current controller).

Returns

HttpResponseOptionsBuilder<TDomain>

Remarks

This method is not trim-safe / AOT-safe because MVC's ControllerLinkGeneratorExtensions is not annotated. Use CreatedAtRoute(string, Func<TDomain, RouteValueDictionary>) with a named route instead for AOT scenarios.

CreatedAtRoute(string, Func<TDomain, RouteValueDictionary>)

Returns 201 Created with a Location header generated via LinkGenerator.GetUriByName (resolved from HttpContext.RequestServices at execute time).

public HttpResponseOptionsBuilder<TDomain> CreatedAtRoute(string routeName, Func<TDomain, RouteValueDictionary> routeValues)

Parameters

routeName string

The route name.

routeValues Func<TDomain, RouteValueDictionary>

A function that returns a RouteValueDictionary for the new resource. Pass a RouteValueDictionary rather than an anonymous type to remain AOT-compatible.

Returns

HttpResponseOptionsBuilder<TDomain>

EvaluatePreconditions()

Honors RFC 9110 conditional request headers (If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since) on the response side. Only meaningful for safe methods (GET/HEAD); on unsafe methods the precondition must be evaluated before the mutation.

public HttpResponseOptionsBuilder<TDomain> EvaluatePreconditions()

Returns

HttpResponseOptionsBuilder<TDomain>

HonorPrefer()

Honors RFC 7240 Prefer: return=minimal/representation. Always emits Vary: Prefer (appended; existing values preserved) and emits Preference-Applied only when honored.

public HttpResponseOptionsBuilder<TDomain> HonorPrefer()

Returns

HttpResponseOptionsBuilder<TDomain>

Vary(params string[])

Appends the named headers to the response Vary header (existing values preserved).

public HttpResponseOptionsBuilder<TDomain> Vary(params string[] headers)

Parameters

headers string[]

Returns

HttpResponseOptionsBuilder<TDomain>

WithAcceptRanges(string)

Sets the Accept-Ranges response header (e.g. "bytes" or "none").

public HttpResponseOptionsBuilder<TDomain> WithAcceptRanges(string acceptRanges)

Parameters

acceptRanges string

Returns

HttpResponseOptionsBuilder<TDomain>

WithContentLanguage(params string[])

Adds languages to the response Content-Language header.

public HttpResponseOptionsBuilder<TDomain> WithContentLanguage(params string[] languages)

Parameters

languages string[]

Returns

HttpResponseOptionsBuilder<TDomain>

WithContentLocation(Func<TDomain, string>)

Sets the Content-Location header from the domain value.

public HttpResponseOptionsBuilder<TDomain> WithContentLocation(Func<TDomain, string> selector)

Parameters

selector Func<TDomain, string>

Returns

HttpResponseOptionsBuilder<TDomain>

WithETag(Func<TDomain, string>)

Sets a strong ETag derived from the domain value.

public HttpResponseOptionsBuilder<TDomain> WithETag(Func<TDomain, string> selector)

Parameters

selector Func<TDomain, string>

Returns

HttpResponseOptionsBuilder<TDomain>

WithETag(Func<TDomain, EntityTagValue>)

Sets an ETag (strong or weak) derived from the domain value.

public HttpResponseOptionsBuilder<TDomain> WithETag(Func<TDomain, EntityTagValue> selector)

Parameters

selector Func<TDomain, EntityTagValue>

Returns

HttpResponseOptionsBuilder<TDomain>

WithErrorMapping(Func<Error, int>)

Per-call override mapper for failure responses. Highest precedence.

public HttpResponseOptionsBuilder<TDomain> WithErrorMapping(Func<Error, int> mapper)

Parameters

mapper Func<Error, int>

Returns

HttpResponseOptionsBuilder<TDomain>

WithErrorMapping<TError>(int)

Per-call override for a single error type. Higher precedence than the global TrellisAspOptions.

public HttpResponseOptionsBuilder<TDomain> WithErrorMapping<TError>(int statusCode) where TError : Error

Parameters

statusCode int

Returns

HttpResponseOptionsBuilder<TDomain>

Type Parameters

TError

WithLastModified(Func<TDomain, DateTimeOffset>)

Sets the Last-Modified header from the domain value.

public HttpResponseOptionsBuilder<TDomain> WithLastModified(Func<TDomain, DateTimeOffset> selector)

Parameters

selector Func<TDomain, DateTimeOffset>

Returns

HttpResponseOptionsBuilder<TDomain>

WithRange(Func<TDomain, ContentRangeHeaderValue>)

Returns 206 Partial Content with Content-Range header for partial ranges.

public HttpResponseOptionsBuilder<TDomain> WithRange(Func<TDomain, ContentRangeHeaderValue> selector)

Parameters

selector Func<TDomain, ContentRangeHeaderValue>

Returns

HttpResponseOptionsBuilder<TDomain>

WithRange(long, long, long)

Returns 206 Partial Content for the given byte range, or 200 OK if it covers the whole resource.

public HttpResponseOptionsBuilder<TDomain> WithRange(long from, long to, long totalLength)

Parameters

from long
to long
totalLength long

Returns

HttpResponseOptionsBuilder<TDomain>