Send request to a service
APPLIES TO: Developer | Premium
The set-backend-service
policy sets the target URL for the current request to http://localhost:3500/v1.0/invoke/{app-id}[.{ns-name}]/method/{method-name}
, replacing template parameters with values specified in the policy statement.
The policy assumes that Dapr runs in a sidecar container in the same pod as the gateway. Upon receiving the request, Dapr runtime performs service discovery and actual invocation, including possible protocol translation between HTTP and gRPC, retries, distributed tracing, and error handling. Learn more about Dapr integration with API Management.
Note
Set the policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.
Policy statement
<set-backend-service backend-id="dapr" dapr-app-id="app-id" dapr-method="method-name" dapr-namespace="ns-name" />
Attributes
Attribute | Description | Required | Default |
---|---|---|---|
backend-id | Must be set to "dapr". | Yes | N/A |
dapr-app-id | Name of the target microservice. Used to form the appId parameter in Dapr. Policy expressions are allowed. | Yes | N/A |
dapr-method | Name of the method or a URL to invoke on the target microservice. Maps to the method-name parameter in Dapr. Policy expressions are allowed. | Yes | N/A |
dapr-namespace | Name of the namespace the target microservice is residing in. Used to form the appId parameter in Dapr. Policy expressions are allowed. | No | N/A |
Usage
- Policy sections: inbound
- Policy scopes: global, product, API, operation
- Gateways: self-hosted
Usage notes
Dapr support must be enabled in the self-hosted gateway.
Example
The following example demonstrates invoking the method named "back" on the microservice called "echo". The set-backend-service
policy sets the destination URL to http://localhost:3500/v1.0/invoke/echo.echo-app/method/back
. The forward-request
policy dispatches the request to the Dapr runtime, which delivers it to the microservice.
The forward-request
policy is shown here for clarity. The policy is typically "inherited" from the global scope via the base
keyword.
<policies>
<inbound>
<base />
<set-backend-service backend-id="dapr" dapr-app-id="echo" dapr-method="back" dapr-namespace="echo-app" />
</inbound>
<backend>
<forward-request />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Related policies
Related content
For more information about working with policies, see:
- Tutorial: Transform and protect your API
- Policy reference for a full list of policy statements and their settings
- Policy expressions
- Set or edit policies
- Reuse policy configurations
- Policy snippets repo
- Azure API Management policy toolkit
- Author policies using Microsoft Copilot in Azure