Service invocation API reference

    Dapr provides users with the ability to call other applications that have unique ids. This functionality allows apps to interact with one another via named identifiers and puts the burden of service discovery on the Dapr runtime.

    This endpoint lets you invoke a method in another Dapr enabled app.

    HTTP 响应码

    When a service invokes another service with Dapr, the status code of the called service will be returned to the caller. If there’s a network error or other transient error, Dapr will return a error with the detailed error message.

    In case a user invokes Dapr over HTTP to talk to a gRPC enabled service, an error from the called gRPC service will return as 500 and a successful response will return as 200OK.

    参数说明
    daprPortdapr 端口。
    appIdthe App ID associated with the remote app
    method-namethe name of the method or url to invoke on the remote app

    Request Contents

    1. {
    2. "Content-Type": "application/json"
    3. }

    Within the body of the request place the data you want to send to the service:

    Once your service code invokes a method in another Dapr enabled app, Dapr will send the request, along with the headers and body, to the app on the <method-name> endpoint.

    The Dapr app being invoked will need to be listening for and responding to requests on that endpoint.

    Cross namespace invocation

    On hosting platforms that support namespaces, Dapr app IDs conform to a valid FQDN format that includes the target namespace. For example, the following string contains the app ID (myApp) in addition to the namespace the app runs in (production).

    Namespace supported platforms

    • Kubernetes

    You can invoke the add method on the mathService service by sending the following:

    For a Node app this would look like:

    1. let args = req.body;
    2. const [operandOne, operandTwo] = [Number(args['arg1']), Number(args['arg2'])];
    3. res.send(result.toString());
    4. });

    The response from the remote endpoint will be returned in the response body.

    In case when your service listens on a more nested path (e.g. /api/v1/add), Dapr implements a full reverse proxy so you can append all the necessary path fragments to your request URL like this:

    http://localhost:3500/v1.0/invoke/mathService/method/api/v1/add

    In case you are invoking mathService on a different namespace, you can use the following URL:

    In this URL, is the namespace that mathService is running in.

    下一步