Invoke a POST method on an application
POSThttps://http-prj1234.api.cloud.diagrid.io/v1.0/invoke/:appId/method/:methodName
This endpoint lets you invoke a HTTP POST method on another application.
Request
Path Parameters
appId stringrequired
Possible values: Value must match regular expression ^[a-zA-Z0-9_-]+$
methodName stringrequired
Possible values: Value must match regular expression ^[a-zA-Z0-9_-]+$
- application/json
Bodyrequired
objectobject
Responses
- 200
- 400
- 403
- 500
OK.
Method name not given.
Invocation forbidden by access control.
Request failed.
Authorization: dapr-api-token
name: dapr-api-tokentype: apiKeyin: header
- python
- java
- csharp
- nodejs
- go
- Python
# pip3 install dapr certifi requests
# ---
from dapr.clients import DaprClient
import os
os.environ["DAPR_API_TOKEN"] = "{{ .DaprAPIToken }}"
os.environ["DAPR_HTTP_ENDPOINT"] = "{{ .DaprHTTPEndpoint }}"
os.environ["DAPR_GRPC_ENDPOINT"] = "{{ .DaprGRPCEndpoint }}"
with DaprClient() as d:
resp = d.invoke_method("{{ .AppID }}", "test", data="{\"key\":\"value\"}", http_verb="{{ .Operation }}")
print(resp.data)
- HTTP.CLIENT
- REQUESTS
import http.client
import json
conn = http.client.HTTPSConnection("http-prj1234.api.cloud.diagrid.io")
payload = json.dumps({})
headers = {
'Content-Type': 'application/json',
'dapr-api-token': '<dapr-api-token>'
}
conn.request("POST", "/v1.0/invoke/:appId/method/:methodName", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
ResponseClear