Skip to main content

Signature

function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>

Parameters

input
string | URL | Request
required
The resource to fetch. Can be a URL string, URL object, or a Request object.
init
RequestInit
Optional request configuration.

RequestInit options

method
string
default:"GET"
HTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
headers
HeadersInit
Request headers. Can be a Headers object, plain object, or array of key-value pairs.
body
BodyInit | null
Request body. Supported types: string, Buffer, URLSearchParams, ArrayBuffer, ArrayBufferView (for example Uint8Array), Blob, and FormData.
transport
Transport
Reusable transport context for this request (proxy + emulation settings, with connection behavior handled by the native layer). When provided, you must not also set browser, os, proxy, or insecure.
browser
BrowserProfile
Browser fingerprint profile to use (e.g., 'chrome_142', 'firefox_139').
os
EmulationOS
Operating system to emulate: 'windows', 'macos', 'linux', 'android', 'ios'.
proxy
string
Proxy URL. Support depends on the native layer and proxy scheme.
timeout
number
default:"30000"
Request timeout in milliseconds. Set to 0 to disable the timeout.
signal
AbortSignal
AbortSignal for cancelling the request.
redirect
'follow' | 'manual' | 'error'
default:"follow"
Redirect handling mode.
disableDefaultHeaders
boolean
default:"false"
When true, prevents browser emulation headers from being automatically added.
insecure
boolean
default:"false"
When true, accepts invalid/self-signed certificates. Use only in development.

Response

Returns a Response object with:
  • status: HTTP status code
  • statusText: HTTP status text
  • headers: response headers
  • ok: true if status is 200-299
  • url: final URL after redirects
  • redirected: true if the response is the result of a redirect
  • body: ReadableStream<Uint8Array> or null
  • bodyUsed: true if body has been consumed
  • contentLength: content length from headers, or null
  • cookies: parsed response cookies as Record<string, string | string[]>

Response methods

  • json(): parse body as JSON
  • text(): get body as string
  • arrayBuffer(): get body as ArrayBuffer
  • blob(): get body as Blob
  • formData(): parse body as FormData
  • clone(): clone the response
See /concepts/compatibility-matrix for detailed compatibility notes and intentional deviations.

Convenience helpers

import { get, post, request } from 'wreq-js';
  • get(url, init?) calls fetch(url, { ...init, method: "GET" }).
  • post(url, body?, init?) calls fetch(url, { ...init, method: "POST", body }).
  • request(options) is deprecated and kept for compatibility. Prefer fetch(url, init).

Examples

Basic GET request

import { fetch } from 'wreq-js';

const response = await fetch('https://api.example.com/data', {
  browser: 'chrome_142',
});

const data = await response.json();

POST with JSON body

const response = await fetch('https://api.example.com/submit', {
  method: 'POST',
  browser: 'chrome_142',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'John', email: 'john@example.com' }),
});

POST with form data

const response = await fetch('https://example.com/login', {
  method: 'POST',
  browser: 'chrome_142',
  body: new URLSearchParams({
    username: 'user',
    password: 'pass',
  }),
});

With timeout and abort

const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);

try {
  const response = await fetch('https://example.com/slow', {
    browser: 'chrome_142',
    timeout: 10000,
    signal: controller.signal,
  });
  console.log(await response.text());
} finally {
  clearTimeout(timeoutId);
}

Reuse connections via Transport

import { createTransport, fetch } from "wreq-js";

const transport = await createTransport({ proxy: "http://proxy.example.com:8080" });

try {
  const response = await fetch("https://example.com", { transport });
  console.log(await response.text());
} finally {
  await transport.close();
}

Custom headers without defaults

const response = await fetch('https://api.example.com', {
  browser: 'chrome_142',
  headers: {
    'User-Agent': 'MyBot/1.0',
    'Accept': 'application/json',
  },
  disableDefaultHeaders: true,
});