typed-rest-client Proxy Configuration

← Back to JavaScript / TypeScript Libraries

typed-rest-client is Microsoft’s REST HTTP client for Node.js and browsers, with strong typing and helpers for common REST patterns. Use typed-rest-client with ProxyMesh for typed API clients behind a rotating proxy.

The javascript-proxy-headers package provides createProxyRestClient(), which subclasses the library’s HTTP stack so HTTPS uses ProxyHeadersAgent instead of a plain tunnel agent. Read CONNECT metadata from client.proxyAgent.lastProxyHeaders.

Installation

npm install typed-rest-client javascript-proxy-headers

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

Basic Proxy Configuration

Use createProxyRestClient() with a user agent and your ProxyMesh proxy URL:

import { createProxyRestClient } from 'javascript-proxy-headers/typed-rest-client';

const client = createProxyRestClient({
  userAgent: 'proxymesh-proxy-example',
  proxy: 'http://username:password@proxyhost:31280'
});

const result = await client.get('https://api.ipify.org?format=json');
console.log(result.result);
console.log(client.proxyAgent.lastProxyHeaders?.get('x-proxymesh-ip'));

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

const client = createProxyRestClient({
  userAgent: 'proxymesh-proxy-example',
  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 { createProxyRestClient } from 'javascript-proxy-headers/typed-rest-client';

const client = createProxyRestClient({
  userAgent: 'proxymesh-proxy-example',
  proxy: 'http://username:password@proxyhost:31280',
  proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});

await client.get('https://httpbin.org/ip');
console.log(client.proxyAgent.lastProxyHeaders?.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