HttpClient - itsManeka/amazing-scraper GitHub Wiki

amazing-scraper


amazing-scraper / HttpClient

Interface: HttpClient

Defined in: src/application/ports/HttpClient.ts:23

Port for HTTP operations. Implementations must preserve cookies across requests within the same session.

Methods

get()

get(url, headers?, options?): Promise<HttpResponse>

Defined in: src/application/ports/HttpClient.ts:30

Performs a GET request.

Parameters

url

string

Target URL

headers?

Record<string, string>

Optional request headers

options?

HttpGetOptions

Optional per-request guards (see HttpGetOptions)

Returns

Promise<HttpResponse>


post()

post(url, data, options, headers?): Promise<HttpResponse>

Defined in: src/application/ports/HttpClient.ts:43

Performs a POST request.

Parameters

url

string

Target URL

data

Record<string, unknown>

Key-value payload

options

formEncoded: true serializes as application/x-www-form-urlencoded

formEncoded

boolean

headers?

Record<string, string>

Optional request headers

Returns

Promise<HttpResponse>


resetSession()?

optional resetSession(): void

Defined in: src/application/ports/HttpClient.ts:74

Resets the HTTP session by discarding all accumulated cookies and creating a fresh session state. This operation is idempotent — calling it multiple times in sequence has no side effects beyond the first call.

This method is optional and may not be implemented by all HttpClient instances (e.g., custom implementations provided by consumers). Call-sites that depend on session recycling must check for method availability: if (typeof client.resetSession === 'function')

Returns

void

Remarks

  • Called by session recycling logic to mitigate progressive session degradation observed with repeated requests to Amazon (e.g., empty titles, missing price blocks).
  • Default request headers and other client configuration persist after reset.
  • Emits a log entry at INFO level with key 'HTTP session recycled'.

Example

const client = createHttpClient();
// ... perform requests ...
if (typeof client.resetSession === 'function') {
  client.resetSession(); // Start fresh session
}
⚠️ **GitHub.com Fallback** ⚠️