pageflock, meet Bun.
Use Bun for a small data script or server workflow. This recipe reads a server environment variable, sends one request and checks the response.
Your first connection.
- 01
Use Bun and set WAGGLE_API_KEY in your shell or a local .env file that is excluded from version control.
- 02
Save the Bun example below as waggle.ts and run bun run waggle.ts.
- 03
Inspect the response and credits header. Keep parallel requests within the limits shown in your pageflock account.
Tool reference: Bun documentation ↗
Build the request.
Set the environment variables in your terminal for these code examples. In automation tools, enter the URL and credentials in the tool’s own fields.
const apiKey = Bun.env.WAGGLE_API_KEY;
if (!apiKey) throw new Error("Set WAGGLE_API_KEY");
const response = await fetch("https://pageflock.hyvelabs.tech/api/pageflock/v1/scrape", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url: "https://example.com" }),
signal: AbortSignal.timeout(45000),
});
const result: unknown = await response.json();
if (!response.ok) {
throw new Error(`pageflock HTTP ${response.status}: ${JSON.stringify(result)}`);
}
console.log("Credits used:", response.headers.get("X-PageFlock-Credits-Used") ?? response.headers.get("X-Waggle-Credits-Used"));
console.log(result);
export {};Reading or copying this example does not send a request or use credits.