SKILL.md
readonlyread-only
name
extension-http-outcalls
description
HTTP outcalls performed by the backend canister (not in the frontend).
version
0.1.6
HTTP 外部呼叫
Caffeine AI 的 HTTP 外部呼叫擴充功能。
概述
此技能讓後端容器能夠發送 HTTP GET 和 POST 請求,適合與外部 API 和服務整合。
後端
針對必須在後端執行的 HTTP 外部呼叫:
預先建置的模組 mo:caffeineai-http-outcalls/outcall.mo 無法修改,提供在後端發送 HTTP GET 或 PUT 請求的基本功能。
module {
public type TransformationInput = {
context : Blob;
response : IC.HttpRequestResult;
};
public type TransformationOutput = IC.HttpRequestResult;
public type Transform = query TransformationInput -> async TransformationOutput;
public type Header = {
name: Text;
value: Text;
};
// 用於 IC 在 HTTP 外部呼叫時的回呼轉換輔助函式。
public func transform(input : TransformationInput) : TransformationOutput;
// HTTP GET 請求,附帶轉換回呼函式。
public func httpGetRequest(url : Text, extraHeaders: [Header], transform : Transform) : async Text;
// HTTP POST 請求,指定轉換回呼。
public func httpPostRequest(url : Text, extraHeaders: [Header], body : Text, transform : Transform) : async Text;
};
GET 使用範例:
import OutCall "mo:caffeineai-http-outcalls/outcall";
actor {
public query func transform(input: OutCall.TransformationInput) : async OutCall.TransformationOutput {
OutCall.transform(input);
};
func makeGetOutcall(url: Text) : async Text {
await OutCall.httpGetRequest(url, [], transform);
};
};
提示:Motoko 不直接支援 JSON 解析,建議將 JSON 傳遞到前端進行解析。
POST 用法類似。






