How-To: Invoke services using HTTP

    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.

    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 flag:

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

    1. dapr run --app-id cart --dapr-http-port 3500 --app-port 5000 --app-ssl python app.py

    In Kubernetes, set the dapr.io/app-id annotation on your pod:

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. name: python-app
    4. namespace: default
    5. labels:
    6. app: python-app
    7. spec:
    8. selector:
    9. matchLabels:
    10. app: python-app
    11. template:
    12. metadata:
    13. labels:
    14. annotations:
    15. dapr.io/enabled: "true"
    16. dapr.io/app-id: "cart"
    17. ...

    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)

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

    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:

    1. 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:

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

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

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

    Namespaces

    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:

    See the for more information on namespaces.

    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.