or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Layered HTTP Client

Build a lightweight HTTP client factory that wraps a fetch-compatible library, supports layered defaults, and works with request/response primitives.

Capabilities

Applies base URL and defaults

  • Creating a client with a base URL and default headers uses them for relative path requests while per-call headers override defaults. @test

Supports chained defaults

  • Deriving a client from another client keeps parent defaults and adds new ones, with later layers taking precedence when overlapping headers or base URLs. @test

Accepts Request objects

  • When given a prebuilt Request-like object, the client still applies layered defaults (base URL, headers) and returns a Response reflecting the requested resource. @test

Implementation

@generates

API

export interface ClientDefaults {
  baseUrl?: string;
  headers?: Record<string, string>;
  retry?: number | {
    retries?: number;
    factor?: number;
    maxTimeout?: number;
    minTimeout?: number;
    randomize?: boolean;
  };
}

export interface RequestLike {
  url: string | URL;
  method?: string;
  headers?: Record<string, string>;
  body?: any;
}

export interface HttpClient {
  request(input: string | URL | RequestLike, init?: {
    method?: string;
    headers?: Record<string, string>;
    body?: any;
  }): Promise<Response>;
  withDefaults(overrides: ClientDefaults): HttpClient;
}

export function createHttpClient(defaults?: ClientDefaults): HttpClient;

Dependencies { .dependencies }

make-fetch-happen { .dependency }

HTTP client with fetch-compatible Request/Response primitives and default-layering support.