Middleware

    Dapr allows custom processing pipelines to be defined by chaining a series of middleware components. A request goes through all defined middleware components before it’s routed to user code, and then goes through the defined middleware, in reverse order, before it’s returned to the client, as shown in the following diagram.

    When launched, a Dapr sidecar constructs a middleware processing pipeline. By default the pipeline consists of tracing middleware and CORS middleware. Additional middleware, configured by a Dapr , can be added to the pipeline in the order they are defined. The pipeline applies to all Dapr API endpoints, including state, pub/sub, service invocation, bindings, security and others.

    As with other building block components, middleware components are extensible and can be found in the supported Middleware reference and in the .

    See all middleware components

    Dapr uses to implement its HTTP server. Hence, your HTTP middleware needs to be written as a FastHTTP handler. Your middleware needs to implement a middleware interface, which defines a GetHandler method that returns fasthttp.RequestHandler and error:

    Your middleware component can be contributed to the components-contrib repository.

    After the components-contrib change has been accepted, submit another pull request against the to register the new middleware type. You’ll need to modify runtime.WithHTTPMiddleware method in to register your middleware with Dapr’s runtime.