---
id: gh-extension-http-outcalls
name: "extension-http-outcalls"
url: https://skills.yangsir.net/skill/gh-extension-http-outcalls
author: caffeinelabs
domain: ai-agent-external-interaction
tags: ["http-requests", "api-integration", "backend-development", "external-services"]
install_count: 27500
rating: 4.60 (120 reviews)
github: https://github.com/caffeinelabs/skills/tree/main/skills/extension-http-outcalls
---

# extension-http-outcalls

> 此技能为后端 Canister 提供 HTTP GET 和 POST 请求能力，使其能够与外部 API 和服务进行集成。它简化了后端与第三方系统的通信，无需手动编写复杂的网络请求逻辑，从而加速开发并扩展了 Canister 的功能边界。

**Stats**: 27,500 installs · 4.6/5 (120 reviews)

## Before / After 对比

### 外部 API 集成效率

**Before**:

在没有这个技能之前，用户需要手动编写复杂的网络请求代码和数据处理逻辑，以实现后端 Canister 与外部服务的通信。这不仅耗时，而且容易出错，增加了开发和维护的负担。

**After**:

该 Skill 提供了预构建的 HTTP 请求模块，用户只需简单调用即可实现与外部 API 的集成。此技能显著减少了开发时间，降低了错误率，并提升了后端服务的集成能力。

| Metric | Before | After | Change |
|---|---|---|---|
| 集成时间 | 120分钟 | 15分钟 | -88% |

## Readme

# HTTP Outcalls
HTTP outcalls extension for [Caffeine AI](https://caffeine.ai?utm_source=caffeine-skill&utm_medium=referral).

## 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.

```mo:caffeineai-http-outcalls/outcall
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:

```motoko filepath=src/backend/main.mo
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.


---
*Source: https://skills.yangsir.net/skill/gh-extension-http-outcalls*
*Markdown mirror: https://skills.yangsir.net/api/skill/gh-extension-http-outcalls/markdown*