golem-make-http-request-moonbit

Implements outgoing HTTP requests from MoonBit Golem agents using the WASI HTTP SDK.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-make-http-request-moonbit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-make-http-request-moonbit
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/moonbit/golem-make-http-request-moonbit
Command: npx skills add https://github.com/golemcloud/golem --skill golem-make-http-request-moonbit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Making outgoing HTTP calls from MoonBit Golem agents requires navigating WASI HTTP resource types whose MoonBit API differs significantly from TypeScript and Rust naming, and incorrect usage of constructors, encodings, or resource drop ordering causes compile errors or runtime traps.

Core Features & Use Cases

  • Correct API Reference: Provides the exact MoonBit constructors and methods for Fields, OutgoingRequest, RequestOptions, Method, and Scheme, including common wrong-call pitfalls.
  • Complete Request Patterns: Includes working GET, POST with JSON body, header handling, timeout configuration, error handling, and large-body streaming read loops.
  • Retry and Durability Guidance: Explains status-code-keyed retry policies and atomic blocks for retrying non-2xx responses within Golem's durable execution model.
  • Use Case: A MoonBit Golem agent needs to call an external REST API, parse the JSON response, and automatically retry on 5xx errors while keeping the call durably persisted in Golem's oplog.

Quick Start

Ask the AI to write a MoonBit Golem agent function that makes an authenticated POST request with a JSON body to an external API and reads the full response.

Frequently Asked Questions about golem-make-http-request-moonbit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make an HTTP request from a MoonBit Golem agent?

Import golemcloud/golem_sdk/http and the wasi/http/types package, build an OutgoingRequest with @types.OutgoingRequest::outgoing_request(headers), finish the body, then send it with @http.handle and block on the future's pollable to get the response.

How do I send a POST request with a JSON body in MoonBit?

Set the method with request.set_method(@types.Post), add a Content-Type header via Fields::from_list, write the JSON string through the body's output stream, drop the stream, finish the body, then call @http.handle. Field values must be FixedArray[Byte] encoded with @utf8.encode.

Why does my MoonBit HTTP code fail with type errors on header values?

WASI field-value types are FixedArray[Byte], not Bytes, so b"..." literals do not type-check with Fields::append or from_list. Convert strings using @utf8.encode(s).to_fixedarray(), and never use String::to_bytes() which returns UTF-16LE.

Are HTTP requests from Golem agents automatically durable?

Yes, Golem automatically records outgoing HTTP requests and responses in the agent's oplog, so on replay the recorded response is returned instead of re-executing the network call. No manual durability wrapping is needed.

How do I retry HTTP requests on 5xx errors in Golem?

Define a named retry policy in golem.yaml whose predicate matches the status-code property for values like 500, 502, 503, and 504, with an exponential backoff policy. The host transparently re-sends the request, and POST requests work out of the box since idempotence mode defaults to true.

Why does my MoonBit WASI HTTP code trap at runtime?

WASI HTTP resources have strict drop ordering: the OutputStream must be dropped before finishing the OutgoingBody, and the InputStream must be dropped before finishing the IncomingBody. Dropping resources out of order or failing to finish bodies causes a trap.