Download the PHP package joby/smol-response without Composer
On this page you can find all versions of the php package joby/smol-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joby/smol-response
More information about joby/smol-response
Files in joby/smol-response
Package smol-response
Short Description A straightforward abstraction layer for building and rendering HTTP responses.
License MIT
Informations about the package smol-response
smolResponse
A straightforward, type-safe HTTP response builder for PHP. Build and send HTTP responses with proper headers, cache control, content types, and status codes. Designed to minimize footguns, maximize productivity, and provide useful hinting and IntelliSense features in your IDE.
Features:
- Type-safe response building with fluent interfaces
- First-class cache control headers
- Automatic content type detection and charset handling
- Range request support for efficient streaming
- Built-in content types: strings, JSON, files, callbacks, and empty responses
- Requires PHP 8.4+
Installation
Quick Start
Core Components
Response (Response)
The main response builder. Create responses with various content types and configurations.
Factory Methods:
json($data, $status = 200)- Create JSON responsefile($path, $status = 200)- Create file responseredirect($url, $permanent = false, $preserve_method = false)- Create redirect response
Fluent Methods:
Status (Status)
Type-safe HTTP status codes with standard reason phrases:
Cache Control (CacheControl)
First-class cache control with support for modern caching strategies:
Presets:
publicContent($max_age = 300, $max_stale_age = 86400)- Public HTML pagespublicMedia($max_age = 31536000, $max_stale_age = 31536000)- Public static assetsprivateContent($max_age = 300, $max_stale_age = 600)- Private HTML pagesprivateMedia($max_age = 31536000, $max_stale_age = 31536000)- Private static assetsneverCached()- No caching (CSRF forms, CAPTCHAs)
Headers (Headers)
Normalized header collection with automatic header name formatting:
Content Types
All content types implement ContentInterface with automatic metadata handling.
StringContent
For text and HTML content:
CallbackContent
For dynamic content generation with callbacks:
JsonContent
For JSON responses:
FileContent
For serving files with automatic MIME detection:
EmptyContent
For responses with no body:
Advanced Features
Range Requests
Efficiently serve partial content for video streaming and resumable downloads:
Custom Content Types
Create your own content types by implementing ContentInterface or extending AbstractContent:
Response Rendering
The Renderer handles all HTTP output:
Automatic Header Generation:
Content-Typewith charset for text contentContent-Lengthfor known-size contentContent-Dispositionwith filename for downloadsEtagfrom content hashesLast-Modifiedfrom file modification timesAccept-Rangesfor range-capable contentContent-Rangefor partial content responses
Fluent Response Building
Chain methods for readable response construction:
Content Metadata
All content types provide rich metadata:
Use Cases
Static File Router
Build a simple static file server with aggressive caching:
API Responses
Consistent JSON API responses:
Content Transformations
Transform content before serving:
Dynamic Content Generation
Use callbacks for complex rendering logic:
Requirements
Fully tested on PHP 8.3+, static analysis for PHP 8.1+.
License
MIT License - See LICENSE file for details.