### Start Mock Server (Bash) Source: https://github.com/jbzoo/http-client/blob/master/CLAUDE.md Command to start a Docker-based mock HTTP server, useful for integration testing. It typically runs on port 8087. ```bash make start-mock-server # Start Docker httpbin server on port 8087 ``` -------------------------------- ### Development commands using Make Source: https://github.com/jbzoo/http-client/blob/master/README.md These are `make` commands for setting up the development environment, running tests, and checking code style. It outlines the process for installing dependencies, executing PHPUnit tests, and verifying code style compliance. ```shell make update # Install/update dependencies make test-all # Run tests and code style checks make test # Run PHPUnit tests only make codestyle # Run code style checks only ``` -------------------------------- ### Start Mock HTTP Server using Make Source: https://github.com/jbzoo/http-client/blob/master/README.md This `make` command starts a mock HTTP server for testing purposes. The mock server is based on httpbin and runs on port 8087, allowing developers to simulate HTTP endpoints for testing their HTTP client interactions. ```shell make start-mock-server # Starts httpbin on port 8087 ``` -------------------------------- ### Perform a Simple GET Request with JBZoo HTTP Client Source: https://github.com/jbzoo/http-client/blob/master/README.md This example shows how to quickly make a basic GET request to an API endpoint using the JBZoo HTTP Client. It instantiates the client without configuration and then retrieves the response body and status code, demonstrating basic usage. ```php use JBZoo\HttpClient\HttpClient; // Simple GET request $client = new HttpClient(); $response = $client->request('https://api.github.com/users/octocat'); echo $response->getBody(); // JSON response echo $response->getCode(); // 200 ``` -------------------------------- ### Install JBZoo HTTP Client with Composer Source: https://github.com/jbzoo/http-client/blob/master/README.md This snippet demonstrates how to install the JBZoo HTTP Client library and its recommended Guzzle dependency using Composer. Guzzle is an optional but recommended dependency for enhanced functionality, while the http-client itself is essential. ```sh composer require guzzlehttp/guzzle --no-update # Recommended, but not required composer require jbzoo/http-client ``` -------------------------------- ### Access Response Data and Headers in JBZoo HTTP Client Source: https://github.com/jbzoo/http-client/blob/master/README.md This example demonstrates various ways to access the HTTP response data, including status codes, headers, and the body, using method calls, property access, and array syntax. It also shows how to parse JSON responses and extract specific values using JBZoo/Data integration for flexible data retrieval. ```php // Get status code $code = $response->getCode(); $code = $response->code; $code = $response['code']; // Get headers $headers = $response->getHeaders(); $headers = $response->headers; $headers = $response['headers']; $header = $response->getHeader('X-Custom-Header-Response'); $header = $response->find('headers.x-custom-header-response', 'default-value', 'trim'); // Get response body $body = $response->getBody(); $body = $response->body; $body = $response['body']; // Parse JSON response (uses JBZoo/Data) $json = $response->getJSON(); $value = $json->get('key', 'default', 'trim'); $value = $json->find('key.nested', 'default', 'trim'); ``` -------------------------------- ### Install/Update Dependencies (Bash) Source: https://github.com/jbzoo/http-client/blob/master/CLAUDE.md Commands to manage Composer dependencies for the project. 'make update' is a convenience script, while 'composer update' is the direct command. ```bash make update # Install/update all composer dependencies composer update # Alternative to make update ``` -------------------------------- ### Run Tests and Code Style Checks (Bash) Source: https://github.com/jbzoo/http-client/blob/master/CLAUDE.md Commands for executing tests and code style checks. 'make test-all' runs everything, 'make test' runs PHPUnit, and 'make codestyle' checks style. 'phpunit' runs tests directly. ```bash make test-all # Run all tests and code style checks make test # Run PHPUnit tests only make codestyle # Run code style checks only phpunit # Run tests directly with PHPUnit ``` -------------------------------- ### Configure and Make a POST Request with JBZoo HTTP Client Source: https://github.com/jbzoo/http-client/blob/master/README.md This snippet illustrates how to configure the JBZoo HTTP Client with various options such as authentication, custom headers, driver selection, timeout, and redirect handling. It then performs a POST request to a specified URL with custom data, demonstrating a more advanced usage scenario. ```php use JBZoo\HttpClient\HttpClient; // Configure client (no options required!) $httpClient = new HttpClient([ 'auth' => [ // Simple HTTP auth 'http-user-name', 'http-password' ], 'headers' => [ // Your custom headers 'X-Custom-Header' => 42, ], 'driver' => 'auto', // (Auto|Guzzle5|Guzzle6|Rmccue) 'timeout' => 10, // Wait in seconds 'verify' => false, // Check cert for SSL 'exceptions' => false, // Show exceptions for statuses 4xx and 5xx 'allow_redirects' => true, // Show real 3xx-header or result? 'max_redirects' => 10, // How much to redirect? 'user_agent' => "It's me", // Custom UserAgent ]); // Just request $response = $httpClient->request('http://my.site.com/', [ 'key-1' => 'value-1', 'key-2' => 'value-2' ], 'post'); ``` -------------------------------- ### Execute Parallel HTTP Requests with HttpClient in PHP Source: https://github.com/jbzoo/http-client/blob/master/README.md Demonstrates how to execute multiple HTTP requests in parallel using the JBZoo HTTP Client. It configures various request options such as method, arguments, headers, timeout, and redirection. Returns an array of response objects. ```php use JBZoo\HttpClient\HttpClient; $httpClient = new HttpClient(); $results = $httpClient->multiRequest(array( 'request_0' => 'http://mockbin.org/request', 'request_1' => ['http://mockbin.org/request', [ 'args' => ['key' => 'value'] ]], 'request_2' => ['http://mockbin.org/request', [ 'method' => 'post', 'args' => ['key' => 'value'], 'headers' => [ 'X-Custom-Header' => 42, ], 'timeout' => 10, 'verify' => false, 'exceptions' => false, 'allow_redirects' => true, 'max_redirects' => 10, 'user_agent' => 'JBZoo/Http-Client v1.x-dev' ]] ]); $results['request_0']->getBody(); $results['request_1']->getBody(); $results['request_2']->getBody(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.