Dapr has a 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.
This endpoint lets you invoke a method on a remote Actor.
POST/GET/PUT/DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/method/<method>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
method | the name of the method to invoke on the remote actor |
Example of invoking a method on a remote actor:
curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/method/shoot \
-H "Content-Type: application/json"
Example of invoking a method on a remote actor with a payload:
curl -X POST http://localhost:3500/v1.0/actors/x-wing/33/method/fly \
-H "Content-Type: application/json"
-d '{
"destination": "Hoth"
}'
The response from the remote endpoint will be returned in the request body.
This endpoint lets you save state for a given actor for a given key.
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/state/<key>
Code | Description |
---|---|
201 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
key | key for the state value |
curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/state/location \
-H "Content-Type: application/json"
-d '{
"location": "Alderaan"
}'
This endpoint lets you save an actor's state as a multi item transaction.
Note that this operation is dependant on a state store that supports multi item transactions.
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/state
Code | Description |
---|---|
201 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/state \
-H "Content-Type: application/json"
-d '[
{
"operation": "upsert",
"request": {
"key": "key1",
"value": "myData"
}
},
{
"operation": "delete",
"request": {
"key": "key2"
}
}
]'
This endpoint lets you get the state of a given actor for a given key.
GET http://localhost:3500/v1.0/actors/<actorType>/<actorId>/state/<key>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
key | key for the state value |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/state/location \
-H "Content-Type: application/json"
The above command returns the state:
{
"location": "Alderaan"
}
This endpoint lets you delete the state of a given actor for a given key.
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/state/<key>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
key | key for the state value |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/state/location \
-X "Content-Type: application/json"
This endpoint lets you create a persistent reminder for an actor.
POST,PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
name | the name of the reminder |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
-H "Content-Type: application/json"
-d '{
"data": "someData",
"dueTime": "1m",
"period": "20s"
}'
This endpoint lets get a reminder for an actor
GET http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
name | the name of the reminder to get |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
"Content-Type: application/json"
The above command returns the reminder:
{
"dueTime": "1s",
"period": "5s",
"data": "0",
}
This endpoint lets delete a reminder for an actor
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
name | the name of the reminder to delete |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/reminders/checkRebels \
-X "Content-Type: application/json"
This endpoint lets you create a timer for an actor.
POST,PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
name | the name of the timer |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/timers/checkRebels \
-H "Content-Type: application/json"
-d '{
"data": "someData",
"dueTime": "1m",
"period": "20s",
"callback": "myEventHandler"
}'
This endpoint lets delete a timer for an actor
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
actorType | the actor type |
actorId | the actor id |
name | the name of the timer to delete |
curl http://localhost:3500/v1.0/actors/stormtrooper/50/timers/checkRebels \
-X "Content-Type: application/json"
This endpoint lets you get the registered actors in Dapr.
GET http://localhost:<appPort>/v1.0/dapr/config
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
Parameter | Description |
---|---|
appPort | the application port |
Example of getting the registered actors:
curl -X GET http://localhost:5001/v1.0/dapr/config \
-H "Content-Type: application/json"
This endpoint lets you activate the actor.
POST http://localhost:<appPort>/v1.0/actors/<actorType>/<actorId>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
appPort | the application port |
actorType | the actor type |
actorId | the actor id |
Example of activating the actor:
curl -X POST http://localhost:5001/v1.0/actors/stormtrooper/50 \
-H "Content-Type: application/json"
This endpoint lets you deactivate the actor.
DELETE http://localhost:<appPort>/v1.0/actors/<actorType>/<actorId>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
appPort | the application port |
actorType | the actor type |
actorId | the actor id |
Example of deactivating the actor:
curl -X DELETE http://localhost:5001/v1.0/actors/stormtrooper/50 \
-H "Content-Type: application/json"
This endpoint lets you invokes the actor reminders.
PUT http://localhost:<appPort>/v1.0/actors/<actorType>/<actorId>/method/remind/<reminderName>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
appPort | the application port |
actorType | the actor type |
actorId | the actor id |
reminderName | the name of the reminder |
Example of invoking the actor reminder:
curl -X POST http://localhost:5001/v1.0/actors/stormtrooper/50/method/remind/checkRebels \
-H "Content-Type: application/json"
This endpoint lets you invokes the actor timers.
PUT http://localhost:<appPort>/v1.0/actors/<actorType>/<actorId>/method/timer/<timerName>
Code | Description |
---|---|
200 | Request successful |
500 | Request failed |
404 | Actor not found |
Parameter | Description |
---|---|
appPort | the application port |
actorType | the actor type |
actorId | the actor id |
timerName | the name of the timer |
Example of invoking the actor timer:
curl -X POST http://localhost:5001/v1.0/actors/stormtrooper/50/method/timer/checkRebels \
-H "Content-Type: application/json"
In order to promote visibility into the state of an actor and allow for complex scenarios such as state aggregation, Dapr saves actor state in external 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:
- Dapr 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
Dapr 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 Dapr ID namespace of myapp
.