Router alias http request routing

Use router alias middleware to alias arbitrary http routes to Dapr endpoints

The router alias HTTP middleware component allows you to convert arbitrary HTTP routes arriving into Dapr to valid Dapr API endpoints.

Component format

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: routeralias
  5. spec:
  6. type: middleware.http.routeralias
  7. version: v1
  8. metadata:
  9. # String containing a JSON-encoded or YAML-encoded dictionary
  10. # Each key in the dictionary is the incoming path, and the value is the path it's converted to
  11. - name: "routes"
  12. value: |
  13. {
  14. "/mall/activity/info": "/v1.0/invoke/srv.default/method/mall/activity/info",
  15. "/hello/activity/{id}/info": "/v1.0/invoke/srv.default/method/hello/activity/info",
  16. "/hello/activity/{id}/user": "/v1.0/invoke/srv.default/method/hello/activity/user"
  17. }

In the example above, an incoming HTTP request for /mall/activity/info?id=123 is transformed into /v1.0/invoke/srv.default/method/mall/activity/info?id=123.

Spec metadata fields

FieldDetailsExample
routesString containing a JSON-encoded or YAML-encoded dictionary. Each key in the dictionary is the incoming path, and the value is the path it’s converted to.See example above

Dapr configuration

To be applied, the middleware must be referenced in configuration. See middleware pipelines.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Configuration
  3. metadata:
  4. name: appconfig
  5. spec:
  6. httpPipeline:
  7. handlers:
  8. - name: routeralias
  9. type: middleware.http.routeralias

Last modified October 12, 2023: Update config.toml (#3826) (0ffc2e7)