Download the PHP package tg111/php-request without Composer
On this page you can find all versions of the php package tg111/php-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tg111/php-request
More information about tg111/php-request
Files in tg111/php-request
Package php-request
Short Description A Python php-request HTTP client library for PHP
License MIT
Homepage https://github.com/tg111/php-request
Informations about the package php-request
PHP Request
A Python requests-like HTTP client library for PHP. This library provides an elegant and simple HTTP client with an interface similar to Python's popular requests
library.
Documentation
- English Documentation (Current)
- 中文文档
Features
- Simple and elegant API - Inspired by Python's requests library
- Multiple HTTP methods - GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
- Session support - Persistent cookies, headers, and configuration
- Comprehensive data handling - JSON, form data, multipart uploads
- Cookie management - Automatic cookie handling and custom cookie support
- Custom headers - Set custom headers for requests
- Authentication - Basic, Bearer token, and custom authentication
- SSL support - Configure SSL verification and certificates
- Proxy support - HTTP and HTTPS proxy configuration
- Timeout control - Request and connection timeout settings
- Error handling - Comprehensive exception handling
- No dependencies - Only requires cURL extension
Installation
Install via Composer:
Requirements
- PHP 7.1 or higher
- cURL extension
- JSON extension
Quick Start
Basic Usage
Using Global Functions
Advanced Usage
Custom Headers and Authentication
Cookies
Session Management
Sessions allow you to persist cookies, headers, and other configuration across multiple requests:
Authentication
Error Handling
Response Object
The response object provides various methods to access response data:
Configuration Options
All request methods accept an options array with the following parameters:
Option | Type | Description |
---|---|---|
headers |
array | Custom headers to send |
cookies |
array | Cookies to include |
timeout |
int | Request timeout in seconds |
connect_timeout |
int | Connection timeout in seconds |
proxy |
string | Proxy URL (http://proxy:port) |
proxy_auth |
string | Proxy authentication (user:pass) |
verify |
bool | Verify SSL certificates |
cert |
string | Path to SSL certificate file |
http_version |
string | HTTP version ('1.0', '1.1', '2.0') |
Examples
File Upload
API Client Example
Testing
Run the test suite:
Run tests with coverage:
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Comparison with Python requests
Python requests | PHP PhpRequest |
---|---|
requests.get(url, params=data) |
PhpRequest::get($url, $params) |
requests.post(url, data=data) |
PhpRequest::post($url, $data) |
requests.Session() |
PhpRequest::session() |
response.text |
$response->text() |
response.json() |
$response->json() |
response.status_code |
$response->getStatusCode() |
response.ok |
$response->ok() |
response.headers |
$response->getHeaders() |
Changelog
See CHANGELOG.md for version history.
Support
- 📚 Documentation
- 🐛 Issue Tracker
All versions of php-request with dependencies
ext-curl Version *
ext-json Version *