PHP code example of kduma / content-negotiable-responses

1. Go to this page and download the library: Download kduma/content-negotiable-responses library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kduma / content-negotiable-responses example snippets


// 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(),
    ]);
});