CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-xmlhttprequest

XMLHttpRequest for Node.js that emulates the browser XMLHttpRequest object

Overall
score

75%

Overview
Eval results
Files

task.mdevals/scenario-8/

Event-Driven Request Monitor

Create a small utility that performs an HTTP GET against a provided URL while exposing event-driven lifecycle hooks for observers. It should let callers attach multiple callbacks to key request stages, remove them when no longer needed, and emit a custom completion signal with summary data once the response arrives.

Capabilities

Lifecycle listeners

  • When start is invoked, two callbacks registered for the "start" stage both run before any response data is returned, and the call resolves with the full response text. @test

Listener removal

  • If a listener is unsubscribed before completion, it never runs, while other callbacks for the same stage still fire in registration order. @test

Completion broadcast

  • After a successful response, a custom "completed" event is emitted to subscribed handlers carrying the final status code and body length. @test

Abort handling

  • When the request is aborted mid-flight, abort-stage listeners run and the completion event is not emitted. @test

Implementation

@generates

API

export type RequestEvent = { type: string; data?: any };

export interface RequestMonitor {
  start(): Promise<string>;
  abort(): void;
  on(eventName: string, handler: (event: RequestEvent) => void): void;
  off(eventName: string, handler: (event: RequestEvent) => void): void;
  trigger(eventName: string, data?: any): void;
}

export function createRequestMonitor(
  url: string,
  options?: { headers?: Record<string, string> }
): RequestMonitor;

Dependencies { .dependencies }

xmlhttprequest { .dependency }

Provides a browser-style HTTP request object whose event system powers the monitor's lifecycle hooks.

Install with Tessl CLI

npx tessl i tessl/npm-xmlhttprequest

tile.json