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-2/

Async Resource Client

Build a small client module that performs asynchronous HTTP requests for common CRUD-style actions against a JSON resource endpoint and exposes parsed responses.

Capabilities

Base URL and async lifecycle

  • A GET to /items/42 resolves asynchronously using the configured base URL and returns the parsed JSON body with status 200. @test
  • A HEAD to /items/42 completes without a body, sends caller-provided headers, and returns the response headers. @test

Writing data

  • A POST to /items sends the provided JSON payload and resolves with the created representation and status 201. @test
  • A PUT to /items/42 sends the provided JSON payload and returns the updated representation and status 200. @test

Deletion

  • A DELETE to /items/42 completes asynchronously with status 204 and an empty body. @test

Implementation

@generates

API

export type HttpHeaders = Record<string, string>;

export type HttpResult = {
  status: number;
  body?: any;
  headers: HttpHeaders;
};

export interface ResourceClient {
  get(path: string, headers?: HttpHeaders): Promise<HttpResult>;
  post(path: string, data: any, headers?: HttpHeaders): Promise<HttpResult>;
  put(path: string, data: any, headers?: HttpHeaders): Promise<HttpResult>;
  remove(path: string, headers?: HttpHeaders): Promise<HttpResult>;
  head(path: string, headers?: HttpHeaders): Promise<HttpResult>;
}

export function createResourceClient(baseUrl: string, defaultHeaders?: HttpHeaders): ResourceClient;

Dependencies { .dependencies }

xmlhttprequest { .dependency }

Provides a browser-style HTTP request interface for Node.js.

Install with Tessl CLI

npx tessl i tessl/npm-xmlhttprequest

tile.json