HttpClient - itsManeka/amazing-scraper GitHub Wiki
amazing-scraper / HttpClient
Defined in: src/application/ports/HttpClient.ts:23
Port for HTTP operations. Implementations must preserve cookies across requests within the same session.
get(
url,headers?,options?):Promise<HttpResponse>
Defined in: src/application/ports/HttpClient.ts:30
Performs a GET request.
string
Target URL
Record<string, string>
Optional request headers
Optional per-request guards (see HttpGetOptions)
Promise<HttpResponse>
post(
url,data,options,headers?):Promise<HttpResponse>
Defined in: src/application/ports/HttpClient.ts:43
Performs a POST request.
string
Target URL
Record<string, unknown>
Key-value payload
formEncoded: true serializes as application/x-www-form-urlencoded
boolean
Record<string, string>
Optional request headers
Promise<HttpResponse>
optionalresetSession():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')
void
- 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'.
const client = createHttpClient();
// ... perform requests ...
if (typeof client.resetSession === 'function') {
client.resetSession(); // Start fresh session
}