class DefaultHttpClient implements HttpClientInterface (View source)

A default implementation of the HttpClientInterface using Guzzle HTTP client.

This class provides a simple way to perform HTTP GET requests and can be easily extended to support other HTTP methods if needed. The constructor initializes the Guzzle client with default settings, including a timeout and a custom User-Agent header to identify the scraper bot when making requests to target websites. Overall, this class serves as a basic HTTP client for the MMA Scrapers project, leveraging the capabilities of the Guzzle library while adhering to the defined interface for consistency and ease of use across the application.

Methods

__construct(Client $client = new Client(['timeout' => 10, 'headers' => ['User-Agent' => 'mma-scrapers']]))

Initializes the DefaultHttpClient with a Guzzle HTTP client.

string
get(string $url)

Perform an HTTP GET request to the specified URL and return the response body as a string.

Details

__construct(Client $client = new Client(['timeout' => 10, 'headers' => ['User-Agent' => 'mma-scrapers']]))

Initializes the DefaultHttpClient with a Guzzle HTTP client.

Parameters

Client $client

string get(string $url)

Perform an HTTP GET request to the specified URL and return the response body as a string.

Parameters

string $url

The URL to send the GET request to.

Return Value

string

The response body from the GET request.