Download the PHP package rehyved/php-http-client without Composer
On this page you can find all versions of the php package rehyved/php-http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rehyved/php-http-client
More information about rehyved/php-http-client
Files in rehyved/php-http-client
Package php-http-client
Short Description An easy to use wrapper for the curl http library in PHP
License MIT
Informations about the package php-http-client
HTTP Client for PHP
A HTTP Client implementation on top of the PHP cURL extension for PHP inspired by the builder pattern.
This library uses a builder pattern similar to the Apache HTTP client Fluent API for Java. The goal is to provide a readable and maintainable way of writing HTTP request logic inside your PHP websites and applications.
Feedback is always welcome.
- Installation
- Usage
- HttpRequest
- Overriding default configuration
- Request types
- GET
- PUT
- POST
- DELETE
- Adding query parameters
- Adding headers
- Adding cookies
- Basic authentication
- Authorization header
- Changing request timeout
- Disabling SSL certificate verification
- HttpResponse
- HttpStatus
Installation
Prerequisites:
- PHP 7.0 or higher
- PHP cURL module (ext-curl)
- PHP DOM module (ext-dom)
This library is available through Packagist and can be imported using Composer:
Usage
The goal with this library is to make it easy to produce HTTP requests in PHP whilst keeping the code readable and understandable. The main starting point for this is the HttpResponse class.
HttpRequest class
The following examples show different usages of the HttpRequest class to perform HTTP requests:
Overriding default configuration
Default configuration for some settings can be configured globally to prevent having to provide these values on each creation of an HttpRequest.
The following configuration options are available by defining the appropriate constants with define():
- RPHC_DEFAULT_HEADERS - An associative array of header name-> header value to be included with each HTTP request (default:
array()
) - RPHC_DEFAULT_TIMEOUT - An int value indicating the number of seconds to use as a timeout for HTTP requests (default:
30
) - RPHC_DEFAULT_VERIFY_SSL_CERTIFICATE - a boolean value indicating if the validity of SSL certificates should be enforced in HTTP requests (default:
true
)
Request types
GET request
[https://httpbin.org]() is a nice service to test HTTP requests against, it provides several ways to try different kinds of requests with a configurable response
PUT request
POST request
DELETE request
Adding query parameters
Adding Headers
Adding Cookies
Basic Authentication
Authorization header
Changing request timeout
Disabling SSL certificate verification
NOTE: This feature is not recommended in a production system but is meant as a convenience option in test environments
HttpResponse class
The $response
variable will hold an instance of HttpResponse.
This type of object holds the resulting content of the HttpRequest and provides useful methods to extract further information.
Status handling
Header handling
Cookie handling
Response body handling
HttpStatus class
This class provides constants to retrieve the matching status code for an HTTP status as well as convenience methods to get the reason phrase and check the type of a status code.
Constants
The class provides constants for the HTTP statuses, for example:
Methods
All versions of php-http-client with dependencies
ext-curl Version *
ext-dom Version *