Class FromResultToHttpResultExtension
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
resultResultThe result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; 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
resultResultThe result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
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
resultTask<Result>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
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
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
Type Parameters
TResultThe 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
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
Type Parameters
TResultThe 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
Type Parameters
TResultThe 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
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- IResult
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe 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
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<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
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultResultThe 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
resultResultThe result to convert.
Returns
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
resultTask<Result>The task producing the result to convert.
Returns
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
resultValueTask<Result>The value task producing the result to convert.
Returns
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
resultTask<Result<TResult>>The task producing the result to convert.
Returns
Type Parameters
TResultThe 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
Returns
Type Parameters
TResultThe 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
resultResult<TResult>The result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultTask<Result<TResult>>The task producing the result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultTask<Result<TResult>>The task producing the result to convert.
mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
asyncMapperis 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
resultValueTask<Result<TResult>>The value task producing the result to convert.
mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
Type Parameters
TResultThe type of the value carried by the result.
TThe 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
mapperis 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
resultResult<TResult>The result to convert.
Returns
- IResult
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe 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
resultResult<TResult>The result to convert.
mapperFunc<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
TResultThe type of the value carried by the result.
TThe 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
mapperis null.