Table of Contents

Class FromResultToHttpResultExtension

Namespace
Arc4u.AspNetCore.Results
Assembly
Arc4u.AspNetCore.Results.dll

Converts a FluentResults.Result or FluentResults.Result<TValue> (or a task of it) into an IResult for minimal API endpoints.

public static class FromResultToHttpResultExtension
Inheritance
FromResultToHttpResultExtension
Inherited Members

Examples

app.MapGet("/orders/{id}", (int id, IOrderService orders) => orders.GetAsync(id).ToHttpOkResultAsync());

Remarks

The ToHttpOkResult family answers 200 OK with the value (or 204 No Content for a non-generic FluentResults.Result); the ToHttpCreatedResult family answers 201 Created with a location. A failed result is turned into a problem result built from the ProblemDetails produced by FromResultToProblemDetailExtension.

The overloads on a Task or ValueTask await it first; the ones on a plain result do not await anything. The overloads with a mapper project the value before it is written to the response. Because the return type is IResult, the possible responses are not visible to OpenAPI; see FromResultToTypedResultExtension for the typed variant.

Methods

ToHttpCreatedResult(Result, Uri?)

Converts the result to an IResult (minimal API): 201 Created with the given location on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpCreatedResult(this Result result, Uri? location)

Parameters

result Result

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

IResult

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync(Result, Uri?)

Converts the result to an IResult (minimal API): 201 Created with the given location on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync(this Result result, Uri? location)

Parameters

result Result

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync(Task<Result>, Uri?)

Awaits the task, then converts the result to an IResult (minimal API): 201 Created with the given location on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync(this Task<Result> result, Uri? location)

Parameters

result Task<Result>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync<TResult>(Result<TResult>, Uri?)

Converts the result to an IResult (minimal API): 201 Created with the given location and the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult>(this Result<TResult> result, Uri? location)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync<TResult>(Task<Result<TResult>>, Uri?)

Awaits the task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult>(this Task<Result<TResult>> result, Uri? location)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync<TResult>(ValueTask<Result<TResult>>, Uri?)

Awaits the value task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static ValueTask<IResult> ToHttpCreatedResultAsync<TResult>(this ValueTask<Result<TResult>> result, Uri? location)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

ValueTask<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, Task<T>>)

Converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)

Converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, Task<T>>)

Awaits the task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, T>)

Awaits the task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, Task<T>>)

Awaits the value task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, T>)

Awaits the value task, then converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static ValueTask<IResult> ToHttpCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

ValueTask<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpCreatedResult<TResult>(Result<TResult>, Uri?)

Converts the result to an IResult (minimal API): 201 Created with the given location and the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpCreatedResult<TResult>(this Result<TResult> result, Uri? location)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

Returns

IResult

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpCreatedResult<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)

Converts the result to an IResult (minimal API): 201 Created with the given location and the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpCreatedResult<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

location Uri

The URI of the created resource, set in the Location header; may be null.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

IResult

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 201 response without location and without content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpOkResult(Result)

Converts the result to an IResult (minimal API): 204 No Content on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpOkResult(this Result result)

Parameters

result Result

The result to convert.

Returns

IResult

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync(Result)

Converts the result to an IResult (minimal API): 204 No Content on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync(this Result result)

Parameters

result Result

The result to convert.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync(Task<Result>)

Awaits the task, then converts the result to an IResult (minimal API): 204 No Content on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync(this Task<Result> result)

Parameters

result Task<Result>

The task producing the result to convert.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync(ValueTask<Result>)

Awaits the value task, then converts the result to an IResult (minimal API): 204 No Content on success, a problem IResult built from the ProblemDetails on failure.

public static ValueTask<IResult> ToHttpOkResultAsync(this ValueTask<Result> result)

Parameters

result ValueTask<Result>

The value task producing the result to convert.

Returns

ValueTask<IResult>

The HTTP response representing the outcome of the result.

Remarks

The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync<TResult>(Task<Result<TResult>>)

Awaits the task, then converts the result to an IResult (minimal API): 200 OK containing the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync<TResult>(this Task<Result<TResult>> result)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync<TResult>(ValueTask<Result<TResult>>)

Awaits the value task, then converts the result to an IResult (minimal API): 200 OK containing the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static ValueTask<IResult> ToHttpOkResultAsync<TResult>(this ValueTask<Result<TResult>> result)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

Returns

ValueTask<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResultAsync<TResult, T>(Result<TResult>, Func<TResult, Task<T>>)

Converts the result to an IResult (minimal API): 200 OK containing the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync<TResult, T>(this Result<TResult> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result Result<TResult>

The result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, Task<T>>)

Awaits the task, then converts the result to an IResult (minimal API): 200 OK containing the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, T>)

Awaits the task, then converts the result to an IResult (minimal API): 200 OK containing the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, T> mapper)

Parameters

result Task<Result<TResult>>

The task producing the result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, Task<T>>)

Awaits the value task, then converts the result to an IResult (minimal API): 200 OK containing the value produced by asyncMapper on success, a problem IResult built from the ProblemDetails on failure.

public static Task<IResult> ToHttpOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

asyncMapper Func<TResult, Task<T>>

Asynchronously maps the value of the result to the value returned to the caller.

Returns

Task<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

asyncMapper is null.

ToHttpOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, T>)

Awaits the value task, then converts the result to an IResult (minimal API): 200 OK containing the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static ValueTask<IResult> ToHttpOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, T> mapper)

Parameters

result ValueTask<Result<TResult>>

The value task producing the result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

ValueTask<IResult>

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.

ToHttpOkResult<TResult>(Result<TResult>)

Converts the result to an IResult (minimal API): 200 OK containing the value of the result on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpOkResult<TResult>(this Result<TResult> result)

Parameters

result Result<TResult>

The result to convert.

Returns

IResult

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

Remarks

A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

ToHttpOkResult<TResult, T>(Result<TResult>, Func<TResult, T>)

Converts the result to an IResult (minimal API): 200 OK containing the value produced by mapper on success, a problem IResult built from the ProblemDetails on failure.

public static IResult ToHttpOkResult<TResult, T>(this Result<TResult> result, Func<TResult, T> mapper)

Parameters

result Result<TResult>

The result to convert.

mapper Func<TResult, T>

Maps the value of the result to the value returned to the caller.

Returns

IResult

The HTTP response representing the outcome of the result.

Type Parameters

TResult

The type of the value carried by the result.

T

The type of the value returned to the caller once mapped.

Remarks

The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with no content. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.

Exceptions

ArgumentNullException

mapper is null.