Download the PHP package abollinger/http without Composer
On this page you can find all versions of the php package abollinger/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abollinger/http
More information about abollinger/http
Files in abollinger/http
Package http
Short Description A library to perform HTTP requests using curl.
License MIT
Informations about the package http
Abollinger\Http\Client
Abollinger\Http\Client is a lightweight, static PHP HTTP client for making GET, POST, PUT, and DELETE requests. It simplifies HTTP interactions with support for custom headers, data payloads, and response parsing (including headers and body).
Features
- Static Methods: Easy-to-use static methods for common HTTP verbs (
get,post,put,delete). - Header Support: Custom headers for requests and parsed response headers.
- JSON Parsing: Automatic JSON decoding for response bodies, with fallback to raw output.
- Error Handling: Clear error messages and HTTP status code validation.
- cURL-Based: Uses PHP’s cURL for reliable and flexible HTTP communication.
Requirements
- PHP 7.4 or higher
- cURL extension enabled
- Composer autoloading
Installation
Include the class via Composer autoloading. Install the Abollinger\Http package using composer. Run the following command:
Then, load the class in your code:
Usage
Making a GET Request
Making a POST Request
Retrieving Headers Only
You can use this method to obtain normalized headers (example: "content type" becomes "Content-Type"):
Handling the Response
The response is always an associative array with the following structure:
Error Handling
If the request fails, the response will include an error key:
API Reference
Static Methods
get(array $params = []): array
Performs a GET request. Returns the parsed response body.
getHeaders(array $params = []): array
Performs a GET request. Returns the parsed response headers.
getNormalizedHeaders(array $params = []): array
Performs a GET request. Normalize and returns the parsed response headers.
post(array $params = []): array
Performs a POST request. Returns the parsed response body.
put(array $params = []): array
Performs a PUT request. Returns the parsed response body.
delete(array $params = []): array
Performs a DELETE request. Returns the parsed response body.
Parameters
All methods accept an associative array of parameters:
| Key | Type | Description |
|---|---|---|
url |
string | Required. The target URL. |
method |
string | HTTP method (GET, POST, PUT, DELETE). Default: GET. |
data |
array | Request payload. Automatically URL-encoded for GET, or sent as-is for POST/PUT. |
headers |
array | Custom headers. Default: ['Content-Type: application/x-www-form-urlencoded']. |
Example Workflow
License
This library is licensed under the MIT License. For full license details, see the LICENSE file distributed with this source code.
Author
Antoine Bollinger Email: [email protected]
For contributions, issues, or feedback, feel free to reach out or open an issue on the relevant repository.