AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Support Minimal API

Open xuzhg opened this issue 1 year ago • 12 comments

Fixes #578

Minimal APIs are a simplified approach for building fast HTTP APIs with ASP.NET Core. You can build fully functioning REST endpoints with minimal code and configuration. Skip traditional scaffolding and avoid unnecessary controllers by fluently declaring API routes and actions. For example, the following code creates an API at the root of the web app that returns the text, "Hello World!".

var app = WebApplication.Create(args);
app.MapGet("/", () => "Hello World!");
app.Run();

Customer want to get the OData query options functionalities. We can provide couple solutions

  1. Get OData JSON payload for minimal API

  2. Enable customer to apply OData query to IQueryable explicitly.

  3. Enable customers to apply OData query to IQueryable implicitly.

xuzhg avatar Dec 15 '23 04:12 xuzhg

Happy to see some progress on minimal API support @xuzhg Would you consider adding more context or a more detailed breakdown of the PR implementation?

Also can you clarify the extent of OData features we support in this PR and what do not support (and do not plan to support). I assume OData routing is not supported at all. Does this support model binding? Delta<T>? Or is support restricted to only ODataQueryOptions<T>?

habbes avatar Jan 04 '24 08:01 habbes

Happy to see some progress on minimal API support @xuzhg Would you consider adding more context or a more detailed breakdown of the PR implementation?

Also can you clarify the extent of OData features we support in this PR and what do not support (and do not plan to support). I assume OData routing is not supported at all. Does this support model binding? Delta? Or is support restricted to only ODataQueryOptions<T>?

Happy to see some progress on minimal API support @xuzhg Would you consider adding more context or a more detailed breakdown of the PR implementation?

Also can you clarify the extent of OData features we support in this PR and what do not support (and do not plan to support). I assume OData routing is not supported at all. Does this support model binding? Delta? Or is support restricted to only ODataQueryOptions<T>?

Thanks for your feedback. Actually, the product codes in the PR changed less.

OData routing

In my understanding, most of customers only want to get the 'OData Query functionalities" when building the minimal API. They don't want to know "Entity Type, Complex Type", or "Entity set, Singleton, Navigation Source, Navigation Property", concepts like these. Even thought they don't want to know about "Key Segement" and It should come after "Collection Segement". So, there's no "OData routing" at all. However, we can add "OData routing" mechanise, for example:

app.MapOData<ODataServiceContext>(EdmModel);

Where, ODataServiceContext is a class containing OData routings.

Does this support model binding?

In my understanding, ASP.NET Core doesn't add model binding for minimal API. So we can't add it. In the minimal API, it only contains the parameter binding, it's same as "model binding" and most of logics are same. For example, You can put [FromBody] on the parameter to bind the parameter from request body. There's new solution to customize the parameter binding. That's what I used in my PR to binding the ODataQueryOptiont< T >.

Delta< T > ? DeltaSet< T >

I think we should support to bind those types. I also added the comments in my PR to support them. It could be a little bit same as ODataQueryOption< T > implementation. It's not complicated but I think let's do it step by step. Before implementing it, let's finish our first BrainStorm on the initial design.

To Be Discussion

OData payload is JSON payload. I think it's time to consider to use Default Json serializer/deserializer. The only thing is to implement the JsonConverter on the OData object. We can sync it more later.

xuzhg avatar Jan 04 '24 20:01 xuzhg

OData payload is JSON payload. I think it's time to consider to use Default Json serializer/deserializer. The only thing is to implement the JsonConverter on the OData object. We can sync it more later.

AntonioBanderasOhGIF

Honestly... this would be the biggest improvement to OData in years and would avoid so many problems.

At the same time... seems ambitious to consider that alongside the Minimal API changes 😅. As much as I want that, I'd avoid doing them together, or potentially even in the same release.

julealgon avatar Jan 16 '24 21:01 julealgon

It would be ABSOLUTELY AMAZING if OData switched to out-of-the-box System.Text.Json serialization with converters. I think it would improve perf by at least 50%, and I wouldn't be surprised if you saw a 200-400% improvement.

Probably needs a separate work branch tho. Hopefully the unit tests are designed to be able to handle this.

Happy to help wherever possible.

robertmclaws avatar Jan 17 '24 02:01 robertmclaws

I agree we stand to gain a lot from leveraging System.Text.Json. But it's not a trivial change given all the scenarios that OData's current serialization supports as well as adherence to the OData spec. However, this is something we're currently looking into. I'll share results from the progress soon. (see: https://github.com/OData/odata.net/issues/2798)

habbes avatar Jan 17 '24 06:01 habbes

Is there any update on this pull-request?

danielpastoor avatar Feb 09 '24 10:02 danielpastoor

Can this please be merged?! I would really like to use minimal API with OData!

cbrianball avatar Aug 28 '24 16:08 cbrianball

One thing I have noticed is that the response from the minimal API endpoints just have the "bare" data. Meaning it doesn't have "@odata.context" field and then the result in a "value" field. If there is a way to have this, please include an example.

cbrianball avatar Aug 29 '24 15:08 cbrianball

One thing I have noticed is that the response from the minimal API endpoints just have the "bare" data. Meaning it doesn't have "@odata.context" field and then the result in a "value" field. If there is a way to have this, please include an example.

That's likely unintentional. That response body is a critical part of the OData protocol and needs to be kept intact.

julealgon avatar Aug 29 '24 16:08 julealgon