Constructor
# new HttpClient()
This class provides functionality to download files from HTTPS URLs. It uses Node.js built-in https module to make requests.
A simple HTTP client for downloading files.
Methods
# async static downloadFile(url)
This method sends a GET request to the specified URL and returns the response body as a string. It handles different scenarios such as non-200 status codes and network errors.
Downloads a file from a given URL.
sequenceDiagram
participant Client
participant HttpClient
participant HTTPS
participant Server
Client->>HttpClient: downloadFile(url)
HttpClient->>HTTPS: get(url)
HTTPS->>Server: GET request
Server-->>HTTPS: Response
HTTPS-->>HttpClient: Response object
alt Status code is 200
loop For each data chunk
HTTPS->>HttpClient: 'data' event
HttpClient->>HttpClient: Accumulate data
end
HTTPS->>HttpClient: 'end' event
HttpClient-->>Client: Resolve with data
else Status code is not 200
HttpClient-->>Client: Reject with error
end
Parameters:
Name | Type | Description |
---|---|---|
url |
The URL of the file to download. |
A promise that resolves with the file content as a string.