Skip to main content
Laravel’s first-party HTTP client wraps Guzzle with a fluent, expressive API. This guide creates a dedicated GeekflareService, registers it in the service container, and injects it into controllers.

Prerequisites

Installation

No extra packages needed — Laravel’s HTTP client is built in. Just add your key to .env:
.env
.env is gitignored by default in Laravel. Use .env.example (without real values) for documentation.

Config file

Centralise the API settings in a config file so they’re accessible via config():
config/geekflare.php

Service class

app/Services/GeekflareService.php

Register in the service container

app/Providers/AppServiceProvider.php

Web Scraping

Controller

app/Http/Controllers/ScrapeController.php

Route

routes/api.php
Test:

Controller

app/Http/Controllers/SearchController.php

Route

routes/api.php
Test:

Screenshot

Controller

app/Http/Controllers/ScreenshotController.php

Route

routes/api.php
Test:

All routes together

routes/api.php

Error handling

Laravel’s HTTP client throw() converts 4xx/5xx responses to RequestException. Handle them by status code:

Common error codes

See Rate Limit Exceeded and Credit Exhausted for strategies to handle these gracefully.

Next steps