Skip to content

Returning status codes from minimal api endpoints #1550

@copyleftproducts

Description

@copyleftproducts

For minimal api endpoints, as implemented in ODataEndpointConventionBuilderExtensions.WithODataResult, it is only possible to return:
-a value that can be serialized in the OData response
-an IResult

It should also be possible to return results like ConflictODataResult, NotFoundODataResult, UpdatedODataResult etc., as is possible from an ODataController.

All the result types that were used in ODataController-based code inherit from ActionResult (and thus shouldn't be used in minimal apis)
The newer ODataMetadataResult, ODataResult and ODataServiceDocumentResult implement IResult, but are internal classes. An ODataResult can only be produced by returning a value from the minimal api endpoint.

Ref. this comment:

// We can figure out more types later, for example, TypedResult<T>, Results<T>, etc.

The responses from Microsoft.AspNetCore.Http.TypedResults (those in the Microsoft.AspNetCore.Http.HttpResults namespace) are not OData formatted, so using those would imply mapping the data from the HttpResults types to equivalent OData IResults.

An alternative could be to
-change the visibility of ODataResult to public
-add new OData results similar to TypedResults/HttpResult
-adapt the code in WithODataResult to return IODataResult, IODataErrorResult similar to how null and IResult is returned

What is the desired solution?

I don't mind creating a PR for it, but it should be aligned with what the design goal for the minimal api is.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions