APICall
Overview
The APICall operator will prepare and send an HTTP request to the specified upstream URL.
If the method, query and path are provided in TempSpace under http_in then they will be used. Otherwise the method defaults to GET.
Message Flows
Message::ReqReply->Message::HTTP: If the origin was an HTTP Request, then pass back an HTTP message with Buffer body, headers and status.Message::Standard: Handlereqreply,sseandwsMessage::Exit: Ifws, close sessionMessage::Error: Passthrough
TempSpace
body, content_type, path, url, and headers are pulled from temp space where the key is the node name from the node_meta.
They override the default values that are provided as settings or in the message sent to this node operator.
The following example shows how the MessageTranslator prepares the data in TempSpace:
nodes:
- id: translate
operator: MessageTranslator
mode: json
in_temp: true
temp_group: mentions
template: |
{
"url": "https://api.twitter.com/2/users/" + settings.USER_ID + "/mentions",
"content_type": "application/json",
"body": {},
"path": "",
"headers": {
"Authorization": "Bearer " + settings.BEARER_TOKEN
}
}
- id: j2b
operator: JSONToBuffer
- id: mentions
operator: APICall
method: GET
url: temp.mentions.urlExamples
Calling Twitter API
name: twitter-mentions
nodes:
- id: start
operator: HTTPIn
method: GET
routes:
- /twitter/mentions
- id: b2j
operator: BufferToJSON
# callout: See if token is already created, if not, create it and store it
# if it is, then use it
# TWITTER_MENTIONS_TRANSLATE_USER_ID = "user_id"
# TWITTER_MENTIONS_TRANSLATE_BEARER_TOKEN = "token"
- id: translate
operator: MessageTranslator
mode: json
in_temp: true
temp_group: token
template: |
{
"url": "https://api.twitter.com/2/users/" + settings.USER_ID + "/mentions?max_results=10&tweet.fields=created_at,author_id,conversation_id,text&user.fields=name,username&expansions=author_id",
"content_type": "application/json",
"body": {},
"path": "",
"headers": {
"Authorization": "Bearer " + settings.BEARER_TOKEN
}
}
- id: j2b
operator: JSONToBuffer
- id: api_call
operator: APICall
method: GET
url: temp.token.url
edges:
- { from: start, to: b2j }
- { from: b2j, to: translate }
- { from: translate, to: j2b }
- { from: j2b, to: api_call }Configuration Reference
name
Must be 'APICall'
Stringrequiredurl
The upstream URL.
Stringrequiredmethod
The method used in the upstream call.
StringoptionalDefault: "GET"path
Optional path that will be used.
Stringoptionalws
Establish a websocket connection
BooleanrequiredDefault: "false"sse
Expect that the upstream call will start a SSE stream
BooleanrequiredDefault: "false"