Skip to content

smmehdisharifi/laravel-msgpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Msgpack

Latest Version on Packagist Total Downloads Tests

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 like response()->json()
  • msgpack middleware to auto-handle request/response
  • Easy Laravel integration via Service Provider
  • Works with Laravel >= 9.x

📚 Table of Contents

🧰 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

About

Laravel Msgpack — MessagePack support for Laravel with response macros and middleware for fast binary serialization.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages