borschphp / http-client
A minimal PSR-18 HTTP Client.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/borschphp/http-client
Requires
- php: ^8.3
- ext-curl: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
Requires (Dev)
- laminas/laminas-diactoros: ^3.6
- mockery/mockery: ^1.6
- pestphp/pest: ^4.1
- phpstan/phpstan: ^2.1
This package is auto-updated.
Last update: 2025-10-10 09:25:29 UTC
README
A minimalist PSR-18 implementation for making HTTP requests in PHP.
Installation
The package can be installed via Composer.
Run the following command:
composer require borschphp/http-client
Usage
Here's a simple example of how to use the Borsch HTTP Client:
<?php require_once __DIR__ . '/vendor/autoload.php'; use Borsch\Http\Client; use Borsch\Http\Adapter\Curl; use Laminas\Diactoros\{RequestFactory, ResponseFactory, StreamFactory}; $adapter = new Curl(new ResponseFactory(), new StreamFactory()); $client = new Client($adapter); $request = (new RequestFactory())->createRequest( 'GET', 'https://jsonplaceholder.typicode.com/posts/1' ); $response = $client->sendRequest($request); echo $response->getBody();
Middlewares
Before
You can add middleware that will be executed before the request is sent:
$adapter = new Curl(new ResponseFactory(), new StreamFactory()); $client = new Client($adapter); $client ->before(function (RequestInterface $request, AdapterInterface $adapter) { // For instance, fetch a JWT Token and add it to the request headers $token = get_jwt_token_from_cache_or_auth_service(); return $request->withHeader('Authorization', 'Bearer ' . $token); })
After
You can also add middleware that will be executed after the response is received:
$client ->after(function (ResponseInterface $response, RequestInterface $request) { // For instance, log the response status code, add a header, modify the body, etc. error_log('Response Status Code: ' . $response->getStatusCode()); return $response->withHeader('X-Processed-Time', time()); });