@scraping-proxy/client
v0.19.0
Published
Lightweight HTTP client for the WireGuard Proxy API.
Downloads
1,994
Readme
@scraping-proxy/client
Lightweight HTTP client for the WireGuard Proxy API.
This package is intended for Node.js >=20 and uses the global fetch API.
What It Provides
WireGuardProxyClientWireGuardProxyClientOptionsActiveProxyTestProxyResult
Basic Usage
import { WireGuardProxyClient } from '@scraping-proxy/client';
const client = new WireGuardProxyClient({
baseUrl: 'http://127.0.0.1:3333',
});
const { proxies } = await client.listProxies();
console.log(proxies);Configuration
WireGuardProxyClient takes:
baseUrl(required): API base URL.proxyHost(optional): host used byproxyUrl(proxy). If omitted, the host is derived frombaseUrl.
const client = new WireGuardProxyClient({
baseUrl: 'https://my-api.example.com',
proxyHost: '10.0.0.5',
});API Methods
listProxies()
Returns all active proxies:
const { proxies } = await client.listProxies();
console.log(proxies[0].configName, proxies[0].proxyUrl);pickProxy()
Returns one selected proxy or null:
const { proxy } = await client.pickProxy();
if (proxy) {
console.log(client.proxyUrl(proxy));
}testProxy(configName)
Tests connectivity for a proxy configuration name:
const result = await client.testProxy('my-config');
if (result.ok) {
console.log('Public IP:', result.ip);
} else {
console.error('Test failed:', result.error);
}proxyUrl(proxy)
Returns the proxy URL provided by the API when available, otherwise falls back to a local URL built from proxyHost and port:
const url = client.proxyUrl(proxy);
console.log(url);Error Handling
All HTTP methods throw when the API responds with a non-2xx status.
try {
await client.listProxies();
} catch (error) {
console.error(error);
}