Skip to main content

Signature

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

Parameters

url
string | URL
required
The URL to fetch. Can be a string or URL 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, and ArrayBufferView (for example Uint8Array).
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. Supports HTTP and SOCKS5 proxies.
timeout
number
Request timeout in milliseconds.
signal
AbortSignal
AbortSignal for cancelling the request.
redirect
'follow'
default:"follow"
Redirect handling mode. Supported: 'follow', 'manual', 'error'.
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
  • body: ReadableStream<Uint8Array> or null
  • bodyUsed: true if body has been consumed

Response methods

  • json(): parse body as JSON
  • text(): get body as string
  • arrayBuffer(): get body as ArrayBuffer
  • clone(): clone the response

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: '[email protected]' }),
});

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);
}

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,
});