Laravel Msgpack brings MessagePack support to Laravel for fast and compact binary data serialization.
It adds encoding/decoding utilities, response macros, and a middleware for API requests and responses using Msgpack.
- Encode/Decode any PHP/Laravel data
response()->msgpack()macro likeresponse()->json()msgpackmiddleware to auto-handle request/response- Easy Laravel integration via Service Provider
- Works with Laravel >= 9.x
- 📦 Installation
- ⚙️ Configuration (Optional)
- 🧠 Basic Usage
- 🧰 Requirements
- 📄 License
- ✨ Credits
- 🤝 Contributing
- 📦 Packagist
- PHP 8.1 or higher
- Laravel 9.x or newer
composer require smmehdisharifi/laravel-msgpackRequires PHP 8.1+ and Laravel 9.x or newer
If you want to publish the config file:
php artisan vendor:publish --tag=msgpack-configuse Msgpack; $data = ['name' => 'Laravel', 'type' => 'framework']; $packed = Msgpack::encode($data); $unpacked = Msgpack::decode($packed);return response()->msgpack([ 'message' => 'Hello from Msgpack!', ]);Sends a binary response with header:
Content-Type: application/x-msgpackRegister middleware in app/Http/Kernel.php:
protected $middlewareAliases = [ 'msgpack' => \SmMehdiSharifi\LaravelMsgpack\Middleware\MsgpackMiddleware::class, ];Apply it to routes:
Route::middleware('msgpack')->post('/api/data', function (Request $request) { return response()->msgpack(['received' => $request->all()]); });This package includes PHPUnit tests using Orchestra Testbench. To run tests:
composer install ./vendor/bin/phpunitThis package is open-sourced software licensed under the MIT license.
Made with ❤️ by Mehdi Sharifi
Inspired by Laravel’s elegant API response system.
Feel free to fork this repo and submit pull requests.
- Found a bug? Open an issue
- Have a feature idea? Let’s discuss it!
- PRs with tests are welcome 🙌
View on Packagist:
https://packagist.org/packages/smmehdisharifi/laravel-msgpack