moddix / serpapi
SerpApi PHP client library
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/moddix/serpapi
Requires
- php: >=8.2
- ext-json: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2026-01-12 17:07:35 UTC
README
A flexible PHP client for interacting with the SerpApi search API. Supports Google and Bing search engines, with extensible options and robust error handling.
Requirements
- PHP 8.2 or higher
- PSR-18 compatible HTTP client (e.g., Symfony HttpClient)
- PSR-17 compatible request factory (e.g., Nyholm/psr7)
Features
- Easy integration with SerpApi for Google and Bing search
- Strongly-typed search options (DTOs) for each engine
- Extensible architecture for adding new search engines
- Comprehensive exception handling (API, network, validation, server errors)
- PSR-18 HTTP client and PSR-17 request factory support
Installation
Install via Composer:
composer require moddix/serpapi
Usage Example
use Moddix\SerpApi\GoogleSearchClient; use Moddix\SerpApi\Dto\GoogleSearchOptions; use Moddix\SerpApi\Dto\SerpApiOptions; use Nyholm\Psr7\Factory\Psr17Factory; use Symfony\Component\HttpClient\Psr18Client; $apiKey = 'your_serpapi_key'; $httpClient = new Psr18Client(); $requestFactory = new Psr17Factory(); $googleOptions = new GoogleSearchOptions(gl: 'us', hl: 'en'); $serpApiOptions = new SerpApiOptions(no_cache: true); $client = new GoogleSearchClient( $apiKey, $httpClient, $requestFactory, $googleOptions, $serpApiOptions ); try { $results = $client->search('pizza'); print_r($results); } catch (\Moddix\SerpApi\Exception\ApiException $e) { // Handle API error } catch (\Moddix\SerpApi\Exception\NetworkException $e) { // Handle network error }
Project Structure
src/— Main source codeDto/— Data Transfer Objects for search optionsEnum/— Enumerations for search parametersException/— Custom exception classes
tests/— PHPUnit tests
Running Tests
Run all tests using PHPUnit:
./vendor/bin/phpunit tests
License
MIT License.