The documentation you are viewing is for Dapr v0.11 which is an older version of Dapr. For up-to-date documentation, see the latest version.

How-To: Invoke and discover services

How-to guide on how to use Dapr service invocation in a distributed application

This article describe how to deploy services each with an unique application ID, so that other services can discover and call endpoints on them using service invocation API.

Step 1: Choose an ID for your service

Dapr allows you to assign a global, unique ID for your app. This ID encapsulates the state for your application, regardless of the number of instances it may have.

In self hosted mode, set the --app-id flag:

dapr run --app-id cart --app-port 5000 python

If your app uses an SSL connection, you can tell Dapr to invoke your app over an insecure SSL connection:

dapr run --app-id cart --app-port 5000 --app-ssl python

Setup an ID using Kubernetes

In Kubernetes, set the annotation on your pod:

apiVersion: apps/v1
kind: Deployment
  name: python-app
  namespace: default
    app: python-app
  replicas: 1
      app: python-app
        app: python-app
      annotations: "true" "cart" "5000"

If your app uses an SSL connection, you can tell Dapr to invoke your app over an insecure SSL connection with the app-ssl: "true" annotation (full list here)

Step 2: Setup a service

The following is a Python example of a cart app. It can be written in any programming language.

from flask import Flask
app = Flask(__name__)

@app.route('/add', methods=['POST'])
def add():
    return "Added!"

if __name__ == '__main__':

This Python app exposes an add() method via the /add endpoint.

Step 3: Invoke the service

Dapr uses a sidecar, decentralized architecture. To invoke an application using Dapr, you can use the invoke API on any Dapr instance.

The sidecar programming model encourages each applications to talk to its own instance of Dapr. The Dapr instances discover and communicate with one another.

From a terminal or command prompt run:

curl http://localhost:3500/v1.0/invoke/cart/method/add -X POST

Since the add endpoint is a ‘POST’ method, we used -X POST in the curl command.

To invoke a ‘GET’ endpoint:

curl http://localhost:3500/v1.0/invoke/cart/method/add

To invoke a ‘DELETE’ endpoint:

curl http://localhost:3500/v1.0/invoke/cart/method/add -X DELETE

Dapr puts any payload returned by the called service in the HTTP response’s body.

dapr invoke --app-id cart --method add


When running on namespace supported platforms, you include the namespace of the target app in the app ID: myApp.production

For example, invoking the example python service with a namespace would be:

curl http://localhost:3500/v1.0/invoke/cart.production/method/add -X POST

See the Cross namespace API spec for more information on namespaces.

Step 4: View traces and logs

The example above showed you how to directly invoke a different service running locally or in Kubernetes. Dapr outputs metrics, tracing and logging information allowing you to visualize a call graph between services, log errors and optionally log the payload body.

For more information on tracing and logs see the observability article.

Last modified July 7, 2022: update nav bar v0.11 (#2633) (b309d3d)