maxiwheat / httpful
A Readable, Chainable, REST friendly, PHP HTTP Client
Requires
- php: >=8.1
- ext-curl: *
Requires (Dev)
- phpstan/phpstan: ^1.9.17
- phpunit/phpunit: ^10.0.7
This package is not auto-updated.
Last update: 2024-11-15 01:57:09 UTC
README
Fork
PHP 8.1 or higher required.
Installation
{ "require": { "maxiwheat/httpful": "^0.4" } }
Local Development
docker compose run --rm httpful bash # In the container shell # Install dependencies composer install # Run tests vendor/bin/phpunit # Run phpstan vendor/bin/phpstan analyse src vendor/bin/phpstan analyse tests
Httpful
Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the features and flexibility to get the job done and make those features really easy to use.
Features
- Readable HTTP Method Support (GET, PUT, POST, DELETE, HEAD, PATCH and OPTIONS)
- Custom Headers
- Automatic "Smart" Parsing
- Automatic Payload Serialization
- Basic Auth
- Client Side Certificate Auth
- Request "Templates"
Sneak Peak
Here's something to whet your appetite. Search the twitter API for tweets containing "#PHP". Include a trivial header for the heck of it. Notice that the library automatically interprets the response as JSON (can override this if desired) and parses it as an array of objects.
// Make a request to the GitHub API with a custom // header of "X-Trvial-Header: Just as a demo". $url = "https://api.github.com/users/maxiwheat"; $response = src\Request::get($url) ->expectsJson() ->withXTrivialHeader('Just as a demo') ->send(); echo "{$response->body->name} joined GitHub on " . date('M jS', strtotime($response->body->created_at)) ."\n";
Installation
Composer
Httpful is PSR-0 compliant and can be installed using composer. Simply add maxiwheat/httpful
to your composer.json file. Composer is the sane alternative to PEAR. It is excellent for managing dependencies in larger projects.
{ "require": { "maxiwheat/httpful": "*" } }
Contributing
Httpful highly encourages sending in pull requests. When submitting a pull request please:
- All pull requests should target the
dev
branch (notmaster
) - Make sure your code follows the coding conventions
- Please use soft tabs (four spaces) instead of hard tabs
- Make sure you add appropriate test coverage for your changes
- Run all unit tests in the test directory via
phpunit ./tests
- Include commenting where appropriate and add a descriptive pull request message