Skip to content

Latest commit

 

History

History
84 lines (53 loc) · 2.64 KB

odatamiddelware.md

File metadata and controls

84 lines (53 loc) · 2.64 KB

ASP.NET Core OData Middleware

Middleware is component that can be assembled into an app pipeline to handle requests and responses. ASP.NET Core OData 8.x has the following middlewares:

ODataBatchMiddleware

This middleware hands OData batch request. Batch requests allow grouping multiple individual requests into a single HTTP request payload.

Batch requests are submitted as a single HTTP POST request to the batch endpoint of a service, located at the URL $batch relative to the service root.

You can call the following extension method to inject batch middleware into pipeline.

app.UseODataBatching();

Batch middlware should add before app.UseRouting();

ODataQueryRequestMiddleware

This middleware hands OData request where the query Options is passing in the request Body.

The query options part of an OData URL can be quite long, potentially exceeding the maximum length of URLs supported by components involved in transmitting or processing the request.

An easier alternative for GET requests is to append /$query to the resource path of the URL, use the POST verb instead of GET, and pass the query options part of the URL in the request body.

You can call the following extension method to inject batch middleware into pipeline.

 app.UseODataQueryRequest();

Query request middlware should add before app.UseRouting();

ODataRouteDebugMiddleware

This middleware provides a debug routing to list the endpoints in the service for easy debug.

You can call the following extension method to inject batch middleware into pipeline.

app.UseODataRouteDebug();

Debug routing middlware should add before app.UseRouting();

Usage

Here's the basic usage:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    // Use odata route debug, /$odata
    app.UseODataRouteDebug();

    // Add OData /$query middleware
    app.UseODataQueryRequest();

    // Add the OData Batch middleware to support OData $Batch
    app.UseODataBatching();
   
    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}