yvesnda / simple_http
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/yvesnda/simple_http
Requires
- ext-curl: *
This package is not auto-updated.
Last update: 2026-01-12 16:16:34 UTC
README
A simple PHP HTTP library with a single helper function for making HTTP requests.
Installation
Install via Composer:
composer require yvesnda/simple_http
Usage
The library provides a single function: http_request.
require 'vendor/autoload.php'; // Example GET request $response = http_request('GET', 'https://api.example.com/data'); // Example POST request with JSON data $response = http_request('POST', 'https://api.example.com/data', [], ['key' => 'value']); // Access response details if ($response['error']) { echo "Error: " . $response['error']; } else { echo "HTTP Code: " . $response['code'] . PHP_EOL; print_r($response['result']); }
Function Signature
http_request($method, $url, $headers = [], $data = '', $follow_response_type = 1)
- $method: HTTP method (
GET,POST,PUT,PATCH,DELETE) - $url: Request URL
- $headers: (optional) Array of headers
- $data: (optional) Array or string of data to send
- $follow_response_type: (optional) If
1, tries to decode JSON/XML responses
Response Structure
The function returns an array with:
code: HTTP status codeheaders: Request headers sentraw: Raw response bodyresult: Parsed response (array for JSON, SimpleXMLElement for XML, or raw string)error: Error message if any
License
MIT License. See LICENSE.