juststeveking / http-slim
A slim psr compliant http client to provide better interoperability
Fund package maintenance!
JustSteveKing
Installs: 1 125
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- ext-json: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.3
- php-parallel-lint/php-parallel-lint: ^1.2
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.1
- squizlabs/php_codesniffer: ^3.5
- symfony/http-client: ^5.0
- symfony/var-dumper: ^5.0
- thecodingmachine/phpstan-safe-rule: ^1.0
Provides
This package is auto-updated.
Last update: 2021-02-04 08:57:43 UTC
README
The purpose of this package is to create an interoperable http client implementation allowing a "bring you own packages" approach to connection to 3rd party services.
THe main goal of this package is to adhere to the following PSRs:
- PSR-18
- PSR-17
- PSR-7
Installation
Using composer:
$ composer require juststeveking/http-slim
You are then free to use it as needed within your projects.
Next steps
The next step is to install a compliant package to do the request itself.
A few packages that are recommended:
Usage
Once you have a client to inject, you can set up an easy to use and consistent implementation. The following example is using the Symfony HttpClient as it has the best documentation I have seen so far.
<?php declare(strict_types=1); use JustSteveKing\HttpSlim\HttpClient; use Symfony\Component\HttpClient\Psr18Client; $httpClient = HttpClient::build( new Psr18Client(), // our client new Psr18Client(), // our request factory new Psr18Client() // our stream factory ); // perform a get request $httpClient->get('https://api.example.com/v1/resource'); // perform a post request $httpClient->post( 'https://api.example.com/v1/resource', ['foo' => 'bar'] ); // perform a put request $httpClient->put( 'https://api.example.com/v1/resource/identifier', ['foo' => 'bar'] ); // perform a patch request $httpClient->patch( 'https://api.example.com/v1/resource/identifier', ['foo' => 'bar'] ); // perform a delete request $httpClient->delete( 'https://api.example.com/v1/resource/identifier' );
Tests
There is a composer script available to run the tests:
$ composer run preflight:test
However, if you are unable to run this please use the following command:
$ ./vendor/bin/phpunit --testdox
Security
If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.