PHP code example of crasp / http
1. Go to this page and download the library: Download crasp/http library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crasp / http example snippets
use Crasp\Http\Client;
$client = Client::create();
$response = $client->get('https://httpbin.org/ip');
//{
// "ip": "1.2.3.4"
//}
use Crasp\Http\Client;
$config = [
'base_uri' => 'https://www.easyhttp.com/apiV2/',
'timeout' => 3000,
'headers' => [
'User-Agent' => 'MyClient/1.0',
'Content-Type' => 'application/json'
]
//...
];
$client = Client::create($config); // or new Client($config);
//...
$config = new Config([
'base_uri' => 'https://www.easyhttp.com/apiV2/',
// array(default)/collection/object/raw
'response_type' => 'collection',
]);
//...
use Crasp\Http\Client;
$client = Client::create();
$logger = new \Monolog\Logger('my-logger');
$logger->pushHandler(
new \Monolog\Handler\RotatingFileHandler('/tmp/my-log.log')
);
$client->pushMiddleware(\GuzzleHttp\Middleware::log(
$logger,
new \GuzzleHttp\MessageFormatter(\GuzzleHttp\MessageFormatter::DEBUG)
));
$response = $client->get('https://httpbin.org/ip');