berlioz / http-client
Berlioz HTTP Client is a PHP library to request HTTP server with continuous navigation, including cookies, sessions...
Installs: 12 398
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.0
- ext-mbstring: *
- ext-zlib: *
- berlioz/http-message: ^2.1
- elgigi/har-parser: ^1.0.0-beta3
- psr/http-client: ^1.0
- psr/log: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/process: ^5.0
Suggests
- ext-curl: To use CURL adapter
- berlioz/html-selector: To query HTML result like jQuery in JavaScript.
Provides
This package is auto-updated.
Last update: 2023-11-14 14:59:50 UTC
README
Berlioz HTTP Client is a PHP library to request HTTP server with continuous navigation, including cookies, sessions... Implements PSR-18 (HTTP Client), PSR-7 (HTTP message interfaces) and PSR-17 (HTTP Factories) standards.
Installation
Composer
You can install Berlioz HTTP Client with Composer, it's the recommended installation.
$ composer require berlioz/http-client
Dependencies
- PHP ^7.1 || ^8.0
- PHP libraries:
- curl
- mbstring
- zlib
- Packages:
- berlioz/http-message
- psr/http-client
- psr/log
Usage
Requests
With RequestInterface
You can construct your own request object whose implements RequestInterface
interface (PSR-7).
use Berlioz\Http\Client\Client; use Berlioz\Http\Message\Request; /** @var \Psr\Http\Message\RequestInterface $request */ $request = new Request(...); $client = new Client(); $response = $client->sendRequest($request); print $response->getBody();
Get/Post/Patch/Put/Delete/Options/Head/Connect/Trace
Methods are available to do request with defined HTTP method:
Client::get(...)
Client::post(...)
Client::patch(...)
Client::put(...)
Client::delete(...)
Client::options(...)
Client::head(...)
Client::connect(...)
Client::trace(...)
Example with Client::get()
:
use Berlioz\Http\Client\Client; $client = new Client(); $response = $client->get('https://getberlioz.com'); print $response->getBody();
You also can pass HTTP method in argument to Client::request(...)
method:
use Berlioz\Http\Client\Client; $client = new Client(); $response = $client->request('get', 'https://getberlioz.com'); print $response->getBody();
History
The browsing history is saved in Client
object.
If you serialize the object Client
, the history is preserve.
Without argument, the method Client::getHistory()
returns an array of complete history:
use Berlioz\Http\Client\Client; $client = new Client(); $history = $client->getHistory();
With argument, the method return a specific request in history.
Cookies
A cookie manager is available to manage cookies of session and between requests.
The manager is available with Client::getCookies()
method.
If you serialize the object Client
, the cookies are preserves.