AnonSocksClient

The AnonSocksClient class provides a way to send HTTP requests through the Anon network using a SOCKS proxy.

Constructor

constructor(anon: Anon, host?: string)

constructor(socksPort: number, host?: string)

Creates a new instance of the AnonSocksClient class.

  • anon: Anon - An instance of the Anon class, or

  • socksPort: number - The SOCKS port to use

  • host: string (optional) - The host to use for the SOCKS proxy. Default: '127.0.0.1'

Methods

get<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>

Sends a GET request to the specified URL through the Anon network.

  • url: string - The URL to send the GET request to

  • config: AxiosRequestConfig (optional) - Additional Axios request configuration Returns: A promise that resolves with the response data

post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>

Sends a POST request to the specified URL through the Anon network.

  • url: string - The URL to send the POST request to

  • data: any (optional) - The data to be sent as the request body

  • config: AxiosRequestConfig (optional) - Additional Axios request configuration Returns: A promise that resolves with the response data

put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>

Sends a PUT request to the specified URL through the Anon network.

  • url: string - The URL to send the PUT request to

  • data: any (optional) - The data to be sent as the request body

  • config: AxiosRequestConfig (optional) - Additional Axios request configuration Returns: A promise that resolves with the response data

delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>

Sends a DELETE request to the specified URL through the Anyone Network.

  • url: string - The URL to send the DELETE request to

  • config: AxiosRequestConfig (optional) - Additional Axios request configuration Returns: A promise that resolves with the response data

patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>

Sends a PATCH request to the specified URL through the Anyone Network.

  • url: string - The URL to send the PATCH request to

  • data: any (optional) - The data to be sent as the request body

  • config: AxiosRequestConfig (optional) - Additional Axios request configuration Returns: A promise that resolves with the response data

Usage Example

import { Anon, AnonSocksClient } from 'your-package-name';

const anon = new Anon();
await anon.start();

const client = new AnonSocksClient(anon);

try {
  const response = await client.get('https://api.example.com/data');
  console.log(response.data);

  const postResponse = await client.post('https://api.example.com/users', { name: 'John Doe' });
  console.log(postResponse.data);
} catch (error) {
  console.error('Error:', error.message);
} finally {
  await anon.stop();
}

Last updated