Download the PHP package flytachi/winter-cast without Composer
On this page you can find all versions of the php package flytachi/winter-cast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package winter-cast
Winter Cast Component
A modern, fluent HTTP client for PHP 8.3+ with a focus on developer experience, type safety, and ease of use.
Features
โจ Fluent API - Chainable, immutable request builder
๐ฏ Type-Safe - Full PHP 8.3+ type declarations
๐ Zero Config - Works out of the box with sensible defaults
๐ Auto-Retry - Exponential backoff with jitter
โก Fast - Powered by cURL for maximum performance
๐ก๏ธ Secure - URL validation, response size limits, timeout controls
๐ Middleware - Intercept requests/responses (logging, auth, retry)
๐๏ธ ApiService - Abstract base class for building API clients
๐ PSR-3 Logging - Built-in LoggingMiddleware
๐ฅ Smart Exceptions - Specific exception types for different errors
Installation
Requirements:
- PHP >= 8.3
- ext-curl
Quick Start
Simple GET Request
POST with JSON
Core Concepts
1. Cast Facade (Simple Usage)
The Cast facade provides a zero-configuration entry point:
Available methods:
get(),post(),put(),patch(),delete(),head()sendGet(),sendPost(),sendPut(),sendPatch(),sendDelete(),sendHead()
2. CastRequest (Request Builder)
Build requests with a fluent interface:
3. CastHeader (Header Builder)
Fluent interface for headers:
Built-in helpers:
json()- Set Accept and Content-Type for JSONauthBearer($token)- Bearer authenticationauthBasic($user, $pass)- Basic authenticationacceptLanguage($lang)- Accept-Language headeruserAgent($agent)- User-Agent headerreferer($url)- Referer headercontentType($type)- Content-Type header
4. CastResponse (Response Object)
Immutable response with helper methods:
Advanced Usage
Query Parameters
Request Body
Timeouts & Retries
Exponential Backoff with Jitter:
- Retry 1: ~1000ms (1s ร 2โฐ ยฑ 30% jitter)
- Retry 2: ~2000ms (1s ร 2ยน ยฑ 30% jitter)
- Retry 3: ~4000ms (1s ร 2ยฒ ยฑ 30% jitter)
Jitter prevents thundering herd problem when multiple clients retry simultaneously.
Error Handling
Exception hierarchy:
CastException- Base exceptionTimeoutException- Request/connection timeoutConnectionException- DNS, connection refused, etc.RequestException- HTTP errors (4xx/5xx)
Dependency Injection
Custom Client Configuration
Middleware
Middleware allows you to intercept and modify requests/responses. Use cases include logging, authentication, caching, and retry logic.
Creating Custom Middleware
Adding Middleware to Client
Using with Facade
Built-in Middleware
Ready-to-use middleware classes in Flytachi\Winter\Cast\Stereotype:
LoggingMiddleware
Logs all HTTP requests and responses with PSR-3 logger:
BearerAuthMiddleware
Automatically adds Bearer token to all requests:
BasicAuthMiddleware
Adds HTTP Basic authentication:
HeadersMiddleware
Adds custom headers to all requests:
RetryOnUnauthorizedMiddleware
Automatically refreshes token on 401 and retries:
ApiService (Abstract Base Class)
Build clean API clients by extending ApiService. Each service has its own isolated CastClient.
Basic Usage
With Custom Client & Middleware
Available Methods
| Method | Description |
|---|---|
get(string $path) |
Create GET request |
post(string $path) |
Create POST request |
put(string $path) |
Create PUT request |
patch(string $path) |
Create PATCH request |
delete(string $path) |
Create DELETE request |
head(string $path) |
Create HEAD request |
client() |
Get service's CastClient |
setClient(CastClient) |
Replace service's client |
tryResult(CastResponse) |
Extract data or throw exception |
Security Features
URL Validation
Automatically validates URLs and rejects dangerous protocols:
Response Size Limit
Prevent memory exhaustion with automatic size limits:
Testing
Examples
GitHub API
Authenticated API Request
File Download
Pagination
License
The MIT License (MIT). Please see License File for more information.
Credits
- Author: Flytachi
- Framework: Winter Framework
- Built with: PHP 8.3+, cURL