Actors API reference

    Dapr provides native, cross-platform and cross-language virtual actor capabilities. Besides the language specific Dapr SDKs, a developer can invoke an actor using the API endpoints below.

    Invoke an actor method through Dapr.

    HTTP Request

    HTTP Response Codes

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    methodThe name of the method to invoke.

    Examples

    Example of invoking a method on an actor:

    1. -H "Content-Type: application/json"

    Example of invoking a method on an actor that takes parameters: You can provided the method parameters and values in the body of the request, for example in curl using -d “{“param”:”value”}”

    1. curl -X POST http://localhost:3500/v1.0/actors/x-wing/33/method/fly \
    2. -H "Content-Type: application/json"
    3. -d '{
    4. "destination": "Hoth"
    5. }'

    or

    1. curl -X POST http://localhost:3500/v1.0/actors/x-wing/33/method/fly \
    2. -H "Content-Type: application/json"
    3. -d "{\"destination\":\"Hoth\"}"

    The response (the method return) from the remote endpoint is returned in the request body.

    Actor state transactions

    Persists the changed to the state for an actor as a multi-item transaction.

    Note that this operation is dependant on a using state store component that supports multi-item transactions.

    HTTP Request

    1. POST/PUT http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/state

    HTTP Response Codes

    CodeDescription
    201Request successful
    400Actor not found
    500Request failed

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.

    Note, all URL parameters are case-sensitive.

    Examples

    1. curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/state \
    2. -H "Content-Type: application/json"
    3. -d '[
    4. {
    5. "operation": "upsert",
    6. "request": {
    7. "key": "key1",
    8. "value": "myData"
    9. }
    10. },
    11. {
    12. "operation": "delete",
    13. "request": {
    14. "key": "key2"
    15. }
    16. }
    17. ]'

    Get actor state

    Gets the state for an actor using a specified key.

    HTTP Request

    1. GET http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/state/<key>

    HTTP Response Codes

    CodeDescription
    200Request successful
    204Key not found, and the response will be empty
    400Actor not found
    500Request failed

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    keyThe key for the state value.

    Note, all URL parameters are case-sensitive.

    Examples

    1. curl http://localhost:3500/v1.0/actors/stormtrooper/50/state/location \
    2. -H "Content-Type: application/json"

    The above command returns the state:

    1. {
    2. "location": "Alderaan"
    3. }

    Create actor reminder

    Creates a persistent reminder for an actor.

    HTTP Request

    1. POST/PUT http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/reminders/<name>

    Body:

    The following specifies a dueTime of 3 seconds and a period of 7 seconds.

    1. {
    2. "dueTime":"0h0m3s0ms",
    3. }

    A dueTime of 0 means to fire immediately. The following body means to fire immediately, then every 9 seconds.

    1. {
    2. "dueTime":"0h0m0s0ms",
    3. "period":"0h0m9s0ms"
    4. }

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    nameThe name of the reminder to create.

    Note, all URL parameters are case-sensitive.

    Examples

    1. curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
    2. -H "Content-Type: application/json"
    3. -d '{
    4. "dueTime": "1m",
    5. "period": "20s"
    6. }'

    Gets a reminder for an actor.

    HTTP Request

    1. GET http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/reminders/<name>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    Examples

    1. curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
    2. "Content-Type: application/json"

    The above command returns the reminder:

    1. {
    2. "dueTime": "1s",
    3. "period": "5s",
    4. "data": "0",
    5. }

    Delete actor reminder

    Deletes a reminder for an actor.

    HTTP Request

    1. DELETE http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/reminders/<name>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    nameThe name of the reminder to delete.

    Note, all URL parameters are case-sensitive.

    Examples

    1. curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
    2. -X "Content-Type: application/json"

    Create actor timer

    Creates a timer for an actor.

    HTTP Request

    1. POST/PUT http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/timers/<name>

    Body:

    The following specifies a dueTime of 3 seconds and a period of 7 seconds.

    1. {
    2. "dueTime":"0h0m3s0ms",
    3. "period":"0h0m7s0ms"
    4. }

    A dueTime of 0 means to fire immediately. The following body means to fire immediately, then every 9 seconds.

    1. {
    2. "dueTime":"0h0m0s0ms",
    3. "period":"0h0m9s0ms"
    4. }

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    nameThe name of the timer to create.

    Note, all URL parameters are case-sensitive.

    Examples

    1. curl http://localhost:3500/v1.0/actors/stormtrooper/50/timers/checkRebels \
    2. -d '{
    3. "data": "someData",
    4. "dueTime": "1m",
    5. "period": "20s",
    6. "callback": "myEventHandler"
    7. }'

    Delete actor timer

    Deletes a timer for an actor.

    HTTP Request

    1. DELETE http://localhost:<daprPort>/v1.0/actors/<actorType>/<actorId>/timers/<name>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    daprPortThe Dapr port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    nameThe name of the timer to delete.

    Note, all URL parameters are case-sensitive.

    Gets the registered actors types for this app and the Dapr actor configuration settings.

    HTTP Request

    1. GET http://localhost:<appPort>/dapr/config

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed

    URL Parameters

    ParameterDescription
    appPortThe application port.

    Examples

    Example of getting the registered actors:

    1. curl -X GET http://localhost:3000/dapr/config \
    2. -H "Content-Type: application/json"

    The above command returns the config (all fields are optional):

    1. {
    2. "entities":["actorType1", "actorType2"],
    3. "actorIdleTimeout": "1h",
    4. "actorScanInterval": "30s",
    5. "drainOngoingCallTimeout": "30s",
    6. "drainRebalancedActors": true
    7. }

    Deactivate actor

    Deactivates an actor by persisting the instance of the actor to the state store with the specified actorId

    HTTP Request

    1. DELETE http://localhost:<appPort>/actors/<actorType>/<actorId>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    appPortThe application port.
    actorTypeThe actor type.
    actorIdThe actor ID.

    Examples

    Example of deactivating an actor: The example deactives the actor type stormtrooper that has actorId of 50

    1. curl -X DELETE http://localhost:3000/actors/stormtrooper/50 \
    2. -H "Content-Type: application/json"

    Invoke actor method

    Invokes a method for an actor with the specified methodName where parameters to the method are passed in the body of the request message and return values are provided in the body of the response message. If the actor is not already running, the app side should it.

    HTTP Request

    1. PUT http://localhost:<appPort>/actors/<actorType>/<actorId>/method/<methodName>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    appPortThe application port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    methodNameThe name of the method to invoke.

    Note, all URL parameters are case-sensitive.

    Examples

    Example of invoking a method for an actor: The example calls the performAction method on the actor type stormtrooper that has actorId of 50

    1. curl -X POST http://localhost:3000/actors/stormtrooper/50/method/performAction \
    2. -H "Content-Type: application/json"

    Invoke reminder

    Invokes a reminder for an actor with the specified reminderName. If the actor is not already running, the app side should it.

    HTTP Request

    1. PUT http://localhost:<appPort>/actors/<actorType>/<actorId>/method/remind/<reminderName>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    appPortThe application port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    reminderNameThe name of the reminder to invoke.

    Note, all URL parameters are case-sensitive.

    Examples

    Example of invoking a reminder for an actor: The example calls the checkRebels reminder method on the actor type stormtrooper that has actorId of 50

    1. curl -X POST http://localhost:3000/actors/stormtrooper/50/method/remind/checkRebels \
    2. -H "Content-Type: application/json"

    Invokes a timer for an actor rwith the specified timerName. If the actor is not already running, the app side should activate it.

    HTTP Request

    1. PUT http://localhost:<appPort>/actors/<actorType>/<actorId>/method/timer/<timerName>

    HTTP Response Codes

    CodeDescription
    200Request successful
    500Request failed
    404Actor not found

    URL Parameters

    ParameterDescription
    appPortThe application port.
    actorTypeThe actor type.
    actorIdThe actor ID.
    timerNameThe name of the timer to invoke.

    Note, all URL parameters are case-sensitive.

    Examples

    Example of invoking a timer for an actor: The example calls the checkRebels timer method on the actor type stormtrooper that has actorId of 50

    1. curl -X POST http://localhost:3000/actors/stormtrooper/50/method/timer/checkRebels \
    2. -H "Content-Type: application/json"

    Health check

    Probes the application for a response to signal to Dapr that the app is healthy and running. Any other response status code other than 200 will be considered as an unhealthy response.

    A response body is not required.

    HTTP Request

    HTTP Response Codes

    URL Parameters

    ParameterDescription
    appPortThe application port.

    Examples

    Example of getting a health check response from the app:

    1. curl -X GET http://localhost:3000/healthz \

    Conceptually, activating an actor means creating the actor’s object and adding the actor to a tracking table. Here is an example from the .NET SDK.

    In order to enable visibility into the state of an actor and allow for complex scenarios such as state aggregation, Dapr saves actor state in external state stores such as databases. As such, it is possible to query for an actor state externally by composing the correct key or query.

    The state namespace created by Dapr for actors is composed of the following items:

    • App ID - Represents the unique ID given to the Dapr application.
    • Actor Type - Represents the type of the actor.
    • Actor ID - Represents the unique ID of the actor instance for an actor type.
    • Key - A key for the specific state value. An actor ID can hold multiple state keys.

    The following example shows how to construct a key for the state of an actor instance under the myapp App ID namespace: myapp||cat||hobbit||food