kduma/content-negotiable-responses

Laravel helpers for creating content-type negotiable responses

Maintainers

Package info

github.com/kduma-OSS/LV-content-negotiable-responses

pkg:composer/kduma/content-negotiable-responses

Statistics

Installs: 34

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v2.0.0 2026-04-08 15:07 UTC

This package is auto-updated.

Last update: 2026-04-08 15:07:48 UTC


README

Latest Stable Version Total Downloads License

Laravel helpers for creating HTTP responses that automatically negotiate content type based on the client's Accept header (JSON, XML, YAML, MsgPack, HTML).

Full documentation: opensource.duma.sh/libraries/php/laravel-content-negotiable-responses

Requirements

  • PHP ^8.3
  • Laravel ^12.0 || ^13.0

Installation

composer require kduma/content-negotiable-responses

Usage

// Returns JSON, XML, YAML or MsgPack depending on the Accept header
Route::get('/api/data', function () {
    return new \KDuma\ContentNegotiableResponses\ArrayResponse([
        'success' => true,
        'timestamp' => time(),
    ]);
});

// Returns HTML in browsers, JSON/XML/YAML in API clients
Route::get('/', function () {
    return new \KDuma\ContentNegotiableResponses\BasicViewResponse('welcome', [
        'user' => auth()->user(),
    ]);
});