wretch Proxy Configuration

← Back to JavaScript / TypeScript Libraries

wretch is a small, chainable wrapper around fetch for browsers and Node.js. Use wretch with ProxyMesh for readable request chains and proxy-backed requests.

The javascript-proxy-headers package provides createProxyWretch(), which registers a custom fetch polyfill so CONNECT headers and response.proxyHeaders work like other adapters. Note: wretch stores polyfills on a module singleton—avoid mixing different proxy configs in one process without coordinating polyfills.

Installation

npm install wretch javascript-proxy-headers

Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install wretch.

Basic Proxy Configuration

Use createProxyWretch() (async), then chain as usual. Responses expose proxyHeaders:

import { createProxyWretch } from 'javascript-proxy-headers/wretch';

const wretch = await createProxyWretch({
  proxy: 'http://username:password@proxyhost:31280'
});

const response = await wretch('https://api.ipify.org?format=json').get().res();
const data = await response.json();
console.log(data);
console.log(response.proxyHeaders.get('x-proxymesh-ip'));

With IP authentication (whitelist your server IP in the dashboard), omit credentials:

const wretch = await createProxyWretch({
  proxy: 'http://proxyhost:port'
});

Custom Proxy Headers

Pass proxyHeaders to send custom headers to the proxy during HTTPS CONNECT (e.g. to select a country with world proxy or open proxy):

import { createProxyWretch } from 'javascript-proxy-headers/wretch';

const wretch = await createProxyWretch({
  proxy: 'http://username:password@proxyhost:31280',
  proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});

const response = await wretch('https://httpbin.org/ip').get().res();
console.log(response.proxyHeaders.get('x-proxymesh-ip'));

ProxyMesh Headers Reference

Send these headers to control proxy behavior:

  • X-ProxyMesh-Country - Route through a specific country (e.g., "US"). Only works with world proxy or open proxy
  • X-ProxyMesh-IP - Request a specific outgoing IP address
  • X-ProxyMesh-Not-IP - Exclude specific IPs from rotation

The proxy returns X-ProxyMesh-IP in the response with the IP address used.

Resources

Related JavaScript / TypeScript Proxy Guides

Explore proxy configuration for other JavaScript / TypeScript HTTP libraries:

Start Free Trial