scon / laravel
SCON — Schema-Compact Object Notation: Laravel integration with response macros, request parsing, and Facade
Requires
- php: >=8.1
- illuminate/support: ^10.0|^11.0|^12.0
- scon/scon: ^1.0
This package is auto-updated.
Last update: 2026-05-16 23:56:22 UTC
README
SCON — Schema-Compact Object Notation for Laravel
Laravel integration for SCON. 59-66% payload reduction, 64% fewer LLM tokens, zero config.
Install
composer require scon/laravel
Auto-discovery registers the service provider and facade. No config file needed.
Usage
Facade
use Scon\Laravel\Facades\SCON; # Encode $scon = SCON::encode(['name' => 'scon', 'version' => 1]); # Decode $data = SCON::decode($sconString); # Minify / Expand $mini = SCON::minify($sconString); $expanded = SCON::expand($mini); # Structural dedup (59-66% reduction on repetitive data) $scon = SCON::encode($data, ['autoExtract' => true]); # Check if Rust extension is loaded $fast = SCON::isAccelerated(); // true if php-scon ext is available
Response macro
# Return SCON response with Content-Type: text/scon return response()->scon($data); return response()->scon($data, 201); return response()->scon($data, 200, ['X-Custom' => 'header']);
Request macros
# Parse SCON request body $data = $request->scon(); # Check if request is SCON if ($request->isScon()) { $data = $request->scon(); }
API example
Route::post('/api/config', function (Request $request) { if ($request->isScon()) { $config = $request->scon(); } else { $config = $request->json()->all(); } return response()->scon([ 'status' => 'saved', 'entries' => count($config), ]); });
Native acceleration
scon/laravel uses scon/scon which auto-detects the Rust native extension when available. No code changes needed — SCON::encode() and SCON::decode() transparently use the tape decoder for near-parity with json_decode.
# Check acceleration status php -r "require 'vendor/autoload.php'; echo Scon\Scon::isAccelerated() ? 'native' : 'pure PHP';"
Performance
Payload reduction on OpenAPI 3.1 spec (71 endpoints):
| Format | Bytes | Ratio |
|---|---|---|
| JSON | 90,886 | 1.00x |
| SCON | 26,347 | 0.29x |
| SCON (minified) | 20,211 | 0.22x |
LLM token efficiency (cl100k_base): 64% fewer tokens — less context window waste for RAG pipelines, tool-use agents, and structured prompts.
Full methodology: DOI 10.5281/zenodo.14733092 Benchmarks, optimization log (21 phases), and industrial protocol fixtures: github.com/QuijoteShin/scon
Also available
- Rust:
cargo add scon— crates.io/crates/scon - JavaScript:
npm install scon-notation— npmjs.com/package/scon-notation - PHP (standalone):
composer require scon/scon— packagist.org/packages/scon/scon
License
MIT