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(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, orsocksPort
:number
- The SOCKS port to usehost
: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>>
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 toconfig
: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>>
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 todata
:any
(optional) - The data to be sent as the request bodyconfig
: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>>
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 todata
:any
(optional) - The data to be sent as the request bodyconfig
: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>>
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 toconfig
: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>>
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 todata
:any
(optional) - The data to be sent as the request bodyconfig
:AxiosRequestConfig
(optional) - Additional Axios request configuration Returns: A promise that resolves with the response data
Usage Example
import { Anon, AnonSocksClient } from '@anyone-protocol/anyone-client';
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