smmehdisharifi / laravel-msgpack
Laravel integration for MessagePack
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/smmehdisharifi/laravel-msgpack
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- rybakit/msgpack: ^0.7
Requires (Dev)
- orchestra/testbench: ^8.15
This package is auto-updated.
Last update: 2025-10-04 13:41:42 UTC
README
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.
π Features
- Encode/Decode any PHP/Laravel data
response()->msgpack()
macro likeresponse()->json()
msgpack
middleware to auto-handle request/response- Easy Laravel integration via Service Provider
- Works with Laravel >= 9.x
π Table of Contents
- π¦ Installation
- βοΈ Configuration (Optional)
- π§ Basic Usage
- π§° Requirements
- π License
- β¨ Credits
- π€ Contributing
- π¦ Packagist
π§° Requirements
- PHP 8.1 or higher
- Laravel 9.x or newer
π¦ Installation
composer require smmehdisharifi/laravel-msgpack
Requires PHP 8.1+ and Laravel 9.x or newer
βοΈ Configuration (Optional)
If you want to publish the config file:
php artisan vendor:publish --tag=msgpack-config
π§ Basic Usage
Encode / Decode
use Msgpack; $data = ['name' => 'Laravel', 'type' => 'framework']; $packed = Msgpack::encode($data); $unpacked = Msgpack::decode($packed);
Response Macro
return response()->msgpack([ 'message' => 'Hello from Msgpack!', ]);
Sends a binary response with header:
Content-Type: application/x-msgpack
Middleware
Register 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()]); });
π§ͺ Testing
This package includes PHPUnit tests using Orchestra Testbench. To run tests:
composer install ./vendor/bin/phpunit
π License
This package is open-sourced software licensed under the MIT license.
β¨ Credits
Made with β€οΈ by Mehdi Sharifi
Inspired by Laravelβs elegant API response system.
π€ Contributing
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 π
π¦ Packagist
View on Packagist:
https://packagist.org/packages/smmehdisharifi/laravel-msgpack