extension-http-outcalls
此技能为后端 Canister 提供 HTTP GET 和 POST 请求能力,使其能够与外部 API 和服务进行集成。它简化了后端与第三方系统的通信,无需手动编写复杂的网络请求逻辑,从而加速开发并扩展了 Canister 的功能边界。
npx skills add https://github.com/caffeinelabs/skills --skill extension-http-outcallsBefore / After 效果对比
1 组在没有这个技能之前,用户需要手动编写复杂的网络请求代码和数据处理逻辑,以实现后端 Canister 与外部服务的通信。这不仅耗时,而且容易出错,增加了开发和维护的负担。
该 Skill 提供了预构建的 HTTP 请求模块,用户只需简单调用即可实现与外部 API 的集成。此技能显著减少了开发时间,降低了错误率,并提升了后端服务的集成能力。
HTTP Outcalls
HTTP outcalls extension for Caffeine AI.
Overview
This skill adds the ability to make HTTP GET and POST requests from the backend canister. Useful for integrating with external APIs and services.
Backend
For HTTP outcalls that must be performed in the backend:
There is the prefabricated module mo:caffeineai-http-outcalls/outcall.mo that that cannot be modified. It provides fundamental functionality for making HTTP GET or PUT requests in the backend.
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;
};
// Helper function for the transform callback used by the IC on HTTP outcalls.
public func transform(input : TransformationInput) : TransformationOutput;
// HTTP GET request with a transform callback function.
public func httpGetRequest(url : Text, extraHeaders: [Header], transform : Transform) : async Text;
// HTTP POST request, specifying a transform callback.
public func httpPostRequest(url : Text, extraHeaders: [Header], body : Text, transform : Transform) : async Text;
};
Usage for 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);
};
};
Hint: JSON parsing is not directly supported in Motoko. Better tunnel JSON to frontend for parsing.
POST usage is analogous.
用户评价 (0)
发表评价
暂无评价
统计数据
用户评分
为此 Skill 评分