smmehdisharifi/laravel-msgpack
最新稳定版本:1.0.0
Composer 安装命令:
composer require smmehdisharifi/laravel-msgpack
包简介
Laravel integration for MessagePack
README 文档
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()msgpackmiddleware 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
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-03