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

1.0.0 2025-06-04 12:47 UTC

This package is auto-updated.

Last update: 2025-10-04 13:41:42 UTC


README

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