Download .zip |
Info | Example | View files (70) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-05-15 (Yesterday) | Not yet rated by the users | Total: Not yet counted | Not yet ranked |
Version | License | PHP version | Categories | |||
httpful 1.0 | MIT/X Consortium ... | 7 | HTTP, PHP 7 |
Description | Author | |
This package can send and process HTTP requests using handler class. |
|
Forked some years ago from nategood/httpful + added support for parallel request and implemented many PSR Interfaces: A Chainable, REST Friendly Wrapper for cURL with many "PSR-HTTP" implemented inferfaces.
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 (SSL) - Request "Download" - Request "Templates" - Parallel Request (via curl_multi) - PSR-3: Logger Interface - PSR-7: HTTP Message Interface - PSR-17: HTTP Factory Interface - PSR-18: HTTP Client Interface
<?php
// Make a request to the GitHub API.
$uri = 'https://api.github.com/users/voku';
$response = \Httpful\Client::get($uri, null, \Httpful\Mime::JSON);
echo $response->getBody()->name . ' joined GitHub on ' . date('M jS Y', strtotime($response->getBody()->created_at)) . "\n";
<?php
// Make a request to the GitHub API with a custom
// header of "X-Foo-Header: Just as a demo".
$uri = 'https://api.github.com/users/voku';
$response = \Httpful\Client::get_request($uri)->withAddedHeader('X-Foo-Header', 'Just as a demo')
->expectsJson()
->send();
$result = $response->getRawBody();
echo $result['name'] . ' joined GitHub on ' . \date('M jS Y', \strtotime($result['created_at'])) . "\n";
<?php
// BasicAuth example with MultiCurl for async requests.
/ @var \Httpful\Response[] $results */
$results = [];
$multi = new \Httpful\ClientMulti(
static function (\Httpful\Response $response, \Httpful\Request $request) use (&$results) {
$results[] = $response;
}
);
$request = (new \Httpful\Request(\Httpful\Http::GET))
->withUriFromString('https://postman-echo.com/basic-auth')
->withBasicAuth('postman', 'password');
$multi->add_request($request);
// $multi->add_request(...); // add more calls here
$multi->start();
// DEBUG
//print_r($results);
composer require voku/httpful
We can override the default parser configuration options be registering a parser with different configuration options for a particular mime type
Example: setting a namespace for the XMLHandler parser
$conf = ['namespace' => 'http://example.com'];
\Httpful\Setup::registerMimeHandler(\Httpful\Mime::XML, new \Httpful\Handlers\XmlMimeHandler($conf));
Handlers are simple classes that are used to parse response bodies and serialize request payloads. All Handlers must implement the MimeHandlerInterface
interface and implement two methods: serialize($payload)
and parse($response)
. Let's build a very basic Handler to register for the text/csv
mime type.
<?php
class SimpleCsvMimeHandler extends \Httpful\Handlers\DefaultMimeHandler
{
/
* Takes a response body, and turns it into
* a two dimensional array.
*
* @param string $body
*
* @return array
*/
public function parse($body)
{
return \str_getcsv($body);
}
/
* Takes a two dimensional array and turns it
* into a serialized string to include as the
* body of a request
*
* @param mixed $payload
*
* @return string
*/
public function serialize($payload)
{
// init
$serialized = '';
foreach ($payload as $line) {
$serialized .= '"' . \implode('","', $line) . '"' . "\n";
}
return $serialized;
}
}
\Httpful\Setup::registerMimeHandler(\Httpful\Mime::CSV, new SimpleCsvMimeHandler());
Finally, you must register this handler for a particular mime type.
\Httpful\Setup::register(Mime::CSV, new SimpleCsvHandler());
After this registering the handler in your source code, by default, any responses with a mime type of text/csv should be parsed by this handler.
Files |
File | Role | Description | ||
---|---|---|---|---|
examples (5 files) | ||||
src (1 directory) | ||||
tests (1 file, 2 directories) | ||||
.editorconfig | Data | Auxiliary data | ||
.scrutinizer.yml | Data | Auxiliary data | ||
.styleci.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
build.sh | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
circle.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE.txt | Doc. | Documentation | ||
phpcs.php_cs | Example | Example script | ||
phpstan.neon | Data | Auxiliary data | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README.md | Doc. | Read m |
Files | / | examples |
File | Role | Description |
---|---|---|
github.php | Example | Example script |
override.php | Class | Class source |
scraping_imdb.php | Example | Example script |
scraping_multi.php | Example | Example script |
xml.php | Example | Example script |
Files | / | src | / | Httpful |
File | Role | Description | ||
---|---|---|---|---|
Curl (3 files) | ||||
Exception (8 files) | ||||
Handlers (8 files) | ||||
Client.php | Class | Class source | ||
ClientMulti.php | Class | Class source | ||
ClientPromise.php | Class | Class source | ||
Encoding.php | Class | Class source | ||
Factory.php | Class | Class source | ||
Headers.php | Class | Class source | ||
Http.php | Class | Class source | ||
Mime.php | Class | Class source | ||
Proxy.php | Class | Class source | ||
Request.php | Class | Class source | ||
Response.php | Class | Class source | ||
ServerRequest.php | Class | Class source | ||
Setup.php | Class | Class source | ||
Stream.php | Class | Class source | ||
UploadedFile.php | Class | Class source | ||
Uri.php | Class | Class source | ||
UriResolver.php | Class | Class source |
Files | / | src | / | Httpful | / | Curl |
File | Role | Description |
---|---|---|
Curl.php | Class | Class source |
MultiCurl.php | Class | Class source |
MultiCurlPromise.php | Class | Class source |
Files | / | src | / | Httpful | / | Exception |
File | Role | Description |
---|---|---|
ClientErrorException.php | Class | Class source |
CsvParseException.php | Class | Class source |
JsonParseException.php | Class | Class source |
NetworkErrorException.php | Class | Class source |
RequestException.php | Class | Class source |
ResponseException.php | Class | Class source |
ResponseHeaderException.php | Class | Class source |
XmlParseException.php | Class | Class source |
Files | / | src | / | Httpful | / | Handlers |
File | Role | Description |
---|---|---|
AbstractMimeHandler.php | Class | Class source |
CsvMimeHandler.php | Class | Class source |
DefaultMimeHandler.php | Class | Class source |
FormMimeHandler.php | Class | Class source |
HtmlMimeHandler.php | Class | Class source |
JsonMimeHandler.php | Class | Class source |
MimeHandlerInterface.php | Class | Class source |
XmlMimeHandler.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
Httpful (12 files) | ||||
static (3 files) | ||||
bootstrap.php | Aux. | Auxiliary script |
Files | / | tests | / | Httpful |
File | Role | Description |
---|---|---|
ClientMultiTest.php | Class | Class source |
ClientPromiseTest.php | Class | Class source |
ClientTest.php | Class | Class source |
DevtoTest.php | Class | Class source |
FactoryTest.php | Class | Class source |
HttpfulTest.php | Class | Class source |
RequestTest.php | Class | Class source |
ResponseTest.php | Class | Class source |
ServerRequestTest.php | Class | Class source |
StreamTest.php | Class | Class source |
UploadedFileTest.php | Class | Class source |
UriTest.php | Class | Class source |
Files | / | tests | / | static |
File | Role | Description |
---|---|---|
foo.txt | Doc. | Documentation |
test.json | Data | Auxiliary data |
test_image.jpg | Icon | Icon image |
httpful-2020-05-15.zip | |
httpful-2020-05-15.tar.gz | |
Install with Composer |
Needed packages | ||
Class | Download | Why it is needed | Dependency |
---|---|---|---|
Simple HTML DOM | .zip .tar.gz | auto-parsing html output | Required |
Version Control | Unique User Downloads | |||||||
100% |
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.