Actors API reference

Detailed documentation on the actors API

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.

User service code calling dapr

Invoke actor method

Invoke an actor method through Dapr.

HTTP Request

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

HTTP Response Codes

CodeDescription
200Request successful
500Request failed
404Actor not found

URL Parameters

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

Note, all URL parameters are case-sensitive.

Examples

Example of invoking a method on an actor:

  1. curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/method/shoot \
  2. -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. "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. }

To configure the reminder to fire once only, the period should be set to empty string. The following specifies a dueTime of 3 seconds with a period of empty string, which means the reminder will fire in 3 seconds and then never fire again.

  1. {
  2. "dueTime":"0h0m3s0ms",
  3. "period":""
  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. "data": "someData",
  5. "dueTime": "1m",
  6. "period": "20s"
  7. }'

Get actor reminder

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

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

Note, all URL parameters are case-sensitive.

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. -H "Content-Type: application/json"
  3. -d '{
  4. "data": "someData",
  5. "dueTime": "1m",
  6. "period": "20s",
  7. "callback": "myEventHandler"
  8. }'

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.

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

Dapr calling to user service code

Get registered actors

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

ParameterDescription
entitiesThe actor types this app supports.
actorIdleTimeoutSpecifies how long to wait before deactivating an idle actor. An actor is idle if no actor method calls and no reminders have fired on it.
actorScanIntervalA duration which specifies how often to scan for actors to deactivate idle actors. Actors that have been idle longer than the actorIdleTimeout will be deactivated.
drainOngoingCallTimeoutA duration used when in the process of draining rebalanced actors. This specifies how long to wait for the current active actor method to finish. If there is no current actor method call, this is ignored.
drainRebalancedActorsA bool. If true, Dapr will wait for drainOngoingCallTimeout to allow a current actor call to complete before trying to deactivate an actor. If false, do not wait.
  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.

Note, all URL parameters are case-sensitive.

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 activate 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 activate 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"

Invoke timer

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

  1. GET http://localhost:<appPort>/healthz

HTTP Response Codes

CodeDescription
200App is healthy

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 \

Activating an Actor

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.

Querying actor state externally

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

In the example above, we are getting the value for the state key food, for the actor ID hobbit with an actor type of cat, under the App ID namespace of myapp.

Last modified February 16, 2021: Merge pull request #1235 from dapr/update-v0.11 (b4e9fbb)