Download the PHP package osirisgate/http-client without Composer
On this page you can find all versions of the php package osirisgate/http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download osirisgate/http-client
More information about osirisgate/http-client
Files in osirisgate/http-client
Package http-client
Short Description Provides powerful and flexible methods to fetch HTTP resources synchronously or asynchronously.
License MIT
Informations about the package http-client
๐ Osirisgate HTTP Client
Lightweight, elegant HTTP client built with modern PHP. Provides an expressive and extensible wrapper to perform REST API calls using clean, typed interfaces. Aligned with Osirisgate Core standards.
๐ฆ Installation
โ Requirements
- PHP 8.2 or higher
- osirisgate/core
โจ Features
- Simple and expressive methods for HTTP verbs:
GET,POST,PUT,PATCH,DELETE - Structured exception system implementing
ExceptionInterface - Response abstraction through
ResponseInterface - Optional support for:
- Query parameters (
filters) - Custom headers
- Low-level request options
- Query parameters (
๐งโ๐ป How to use it ?
โ Send a GET request
๐ With query parameters
โ๏ธ Create a resource (POST)
๐ Update a resource (PUT / PATCH)
โ Delete a resource
โ๏ธ Advanced Configuration
๐งพ Custom headers
๐ Request options
The options parameter allows for fine-grained control over the underlying HTTP request. Here's a detailed overview of the available options:
timeout: int (default: 30) - Sets the timeout of the request in seconds.max_redirects: int (default: 20) - Specifies the maximum number of redirects to follow.http_version: string|null (default: null) - Sets the HTTP protocol version (e.g., '1.1', '2.0').base_uri: string|null (default: null) - Sets a base URI for resolving relative URLs.headers: array (default: []) - An associative array of HTTP headers.auth_basic: array|null (default: null) - Enables HTTP basic authentication with ['username', 'password'].auth_bearer: string|null (default: null) - Sets the Authorization header with a bearer token.auth_ntlm: array|null (default: null) - Enables NTLM authentication with ['username', 'password'].query: array (default: []) - Associative array of query parameters to append to the URI.body: resource|string|null (default: null) - The raw request body.json: mixed|null (default: null) - If provided, will be JSON-encoded and used as the request body with the correct Content-Type.user_data: mixed|null (default: null) - Arbitrary user-defined data associated with the request.bindto: string|null (default: null) - Binds to a specific network interface or local port.proxy: string|null (default: null) - URI of a proxy server to use.no_proxy: string|null (default: null) - Comma-separated list of hostnames to bypass the proxy.verify_peer: bool (default: true) - Whether to verify the peer's SSL certificate. Set to false with caution in production.verify_host: bool (default: true) - Whether to verify the hostname against the SSL certificate.cafile: string|null (default: null) - Path to a custom CA bundle file for SSL verification.capath: string|null (default: null) - Path to a directory containing CA certificates.local_cert: string|null (default: null) - Path to a client-side certificate file for client authentication.local_pk: string|null (default: null) - Path to the private key file associated with local_cert.passphrase: string|null (default: null) - Passphrase for the private key.ciphers: string|null (default: null) - List of SSL/TLS ciphers to use.peer_fingerprint: array|null (default: null) - Verify the peer's certificate by its fingerprint (e.g., ['sha256' => '...]).capture_peer_cert_chain: bool (default: false) - Capture the peer's certificate chain for inspection via getInfo().extra: array (default: []) - Array of extra options to pass directly to the underlying HTTP client.
๐จ Error Handling
Any HTTP client or server error will throw a typed exception implementing ExceptionInterface.
๐ Response Interface
Each request returns a structured object implementing ResponseInterface.
| Method | Description |
|---|---|
getData() |
Returns data if 'data' key is present. Otherwise, returns empty array. |
get(string $fieldName, mixed $default = null) |
Returns the value of a specific field, otherwise returns $default. |
getStatusCode() |
Returns the HTTP status code |
getHeaders() |
Returns an array of headers |
getContent() |
Returns raw response body (string) |
toArray() |
Returns JSON-decoded response |
cancel() |
Closes the response stream and all related buffers. |
getInfo(?string $type = null) |
Returns meta information (e.g. url) |
๐งช Run Tests
A full suite of unit tests is included and runs against a public API (jsonplaceholder.typicode.com).
๐งฐ Developer Tools
โ Code style
๐ง Static analysis
Or run both checks at once:
๐ License
This package is licensed under the MIT License.
๐ค Author
Ulrich Geraud AHOGLA Software Engineer โ Osirisgate
If you have any questions or suggestions, please contact me via [email protected]