Registry / devops / as-fetch

as-fetch

JSON →
library2.1.4jsnpmunverified

A fetch API implementation for AssemblyScript (WebAssembly) that supports both asynchronous and synchronous HTTP requests. Current stable version is 2.1.4, with periodic releases. Key differentiators: fully typed for AssemblyScript, offers optional synchronous mode via transform, and provides both raw and ESM bindings for host integration. Unlike JavaScript fetch, it requires explicit binding setup and response handler exports. Suitable for AssemblyScript projects needing HTTP client functionality in WebAssembly.

npm install as-fetch
INSTALL
IMPORT
SIG · AS-FETCH
A
as-fetch
devopsjavascriptv2.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetch
import { fetch } from 'as-fetch/assembly';
import { fetch } from 'as-fetch';
The main fetch function is exported from the 'assembly' subpath; the top-level package does not expose fetch directly.
fetchSync
import { fetchSync } from 'as-fetch/sync';
import { fetchSync } from 'as-fetch/assembly';
Synchronous fetch is in a separate subpath 'as-fetch/sync'. Use this only when the synchronous transform is applied.
responseHandler
export { responseHandler } from 'as-fetch/assembly';
import { responseHandler } from 'as-fetch/assembly';
For async fetch, responseHandler must be re-exported from your AssemblyScript module, not imported. It is consumed by the host bindings.
FetchHandler
import { FetchHandler } from 'as-fetch/bindings.raw.esm.js';
import { FetchHandler } from 'as-fetch';
FetchHandler is a JavaScript class from the raw ESM bindings, not available in AssemblyScript imports.

Demonstrates async fetch in AssemblyScript with response handler export and basic usage.

// AssemblyScript file (e.g., index.ts) import { fetch } from "as-fetch/assembly"; export { responseHandler } from "as-fetch/assembly"; export function main(): void { fetch("https://api.example.com/data", { method: "GET", mode: "no-cors", headers: [], body: null, }).then((response) => { const body = response.text(); console.log("Status: " + response.status.toString()); console.log("Body: " + body); }); }
Debug
Known issues
gotchaAsync fetch requires exporting 'responseHandler' from the assembly module; omitting it causes runtime errors.
fix
Add 'export { responseHandler } from 'as-fetch/assembly';' to your module.
affects: >=0.0.0
gotchaSynchronous fetch requires the 'as-fetch/transform' transform to be applied to the asc compiler; otherwise fetchSync will not work.
fix
Add '--transform as-fetch/transform' to asc command or configure in asconfig.json.
affects: >=0.0.0
gotchaThe FetchHandler class must be instantiated with a fetch function (e.g., global fetch) before use; supplying undefined causes bindings to fail.
fix
Ensure fetch is available in the host environment (Node, browser) and pass it to FetchHandler: new FetchHandler(fetch).
affects: >=0.0.0
Errors
Common errors & fixes
Error: responseHandler is not defined or not exported
The AssemblyScript module did not export responseHandler as required by async fetch.
fix
Add 'export { responseHandler } from 'as-fetch/assembly';' to your AssemblyScript entry file.
TypeError: fetchSync is not a function
The synchronous transform was not applied or fetchSync was imported from wrong path.
fix
Ensure you use '--transform as-fetch/transform' in asc command and import fetchSync from 'as-fetch/sync'.
Error: FetchHandler.imports is not an object or undefined
FetchHandler was not instantiated correctly or missing new keyword.
fix
Use 'const Fetch = new FetchHandler(fetch);' and verify fetch is defined.
Upgrade
Version history
2.1.4latest on npm
Audit
Dependencies
assemblyscriptoptionalRuntime dependency for AssemblyScript compilation and execution
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
as-fetch — npm install as-fetch · libregistry