Metadata API reference

Detailed documentation on the Metadata API

Dapr has a metadata API that returns information about the sidecar allowing runtime discoverability. The metadata endpoint returns among other things, a list of the components loaded and the activated actors (if present).

The Dapr metadata API also allows you to store additional information in the format of key-value pairs.

Note: The Dapr metatada endpoint is for instance being used by the Dapr CLI when running dapr in standalone mode to store the PID of the process hosting the sidecar and the command used to run the application.

Get the Dapr sidecar information

Gets the Dapr sidecar information provided by the Metadata Endpoint.

HTTP 请求

GET http://localhost:<daprPort>/v1.0/metadata

URL 参数

参数说明
daprPortDapr 端口。

HTTP 响应码

代码说明
200Metadata information returned
500Dapr could not return the metadata information

HTTP Response Body

Metadata API Response Object

Name数据类型说明
idstringApplication ID
actorsMetadata API Response Registered Actor[]A json encoded array of Registered Actors metadata.
extended.attributeNamestringList of custom attributes as key-value pairs, where key is the attribute name.
组件Metadata API Response Component[]A json encoded array of loaded components metadata.

Metadata API Response Registered Actor

Name数据类型说明
typestringThe registered actor type.
countintegerNumber of actors running.

Metadata API Response Component

Name数据类型说明
namestringName of the component.
typestringComponent type.
versionstring组件版本.

示例

Note: This example is based on the Actor sample provided in the Dapr SDK for Python.

curl http://localhost:3500/v1.0/metadata
{
    "id":"demo-actor",
    "actors":[
        {
            "type":"DemoActor",
            "count":1
        }
    ],
    "extended": {
        "cliPID":"1031040",
        "appCommand":"uvicorn --port 3000 demo_actor_service:app"
    },
    "components":[
        {
            "name":"pubsub",
            "type":"pubsub.redis",
            "version":""
        },
        {
            "name":"statestore",
            "type":"state.redis",
            "version":""
        }
    ]
}

Add a custom attribute to the Dapr sidecar information

Adds a custom attribute to the Dapr sidecar information stored by the Metadata Endpoint.

HTTP 请求

PUT http://localhost:<daprPort>/v1.0/metadata/attributeName

URL 参数

参数说明
daprPortDapr 端口。
attributeNameCustom attribute name. This is they key name in the key-value pair.

HTTP Request Body

In the request you need to pass the custom attribute value as RAW data:

{
  "Content-Type": "text/plain"
}

Within the body of the request place the custom attribute value you want to store:

attributeValue

HTTP 响应码

代码说明
204Custom attribute added to the metadata information

示例

Note: This example is based on the Actor sample provided in the Dapr SDK for Python.

Add a custom attribute to the metadata endpoint:

curl -X PUT -H "Content-Type: text/plain" --data "myDemoAttributeValue" http://localhost:3500/v1.0/metadata/myDemoAttribute

Get the metadata information to confirm your custom attribute was added:

{
    "id":"demo-actor",
    "actors":[
        {
            "type":"DemoActor",
            "count":1
        }
    ],
    "extended": {
        "myDemoAttribute": "myDemoAttributeValue",
        "cliPID":"1031040",
        "appCommand":"uvicorn --port 3000 demo_actor_service:app"
    },
    "components":[
        {
            "name":"pubsub",
            "type":"pubsub.redis",
            "version":""
        },
        {
            "name":"statestore",
            "type":"state.redis",
            "version":""
        }
    ]
}