PHP code example of tequilarapido / api-response

1. Go to this page and download the library: Download tequilarapido/api-response 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/ */

    

tequilarapido / api-response example snippets

 php
Tequilarapido\ApiResponse\ApiResponseServiceProvider::class 
 php
return api_response()->item(['result`' => 'success'])
 php
return api_response()->item(collect(['Apple', 'Orange', 'Kiwi']))
 php
return api_response()->item(collect(['Apple', 'Orange', 'Kiwi']))
 php
class BookTransformer extends TransformerAbstract
{
    public function transform($book)
    {
        return [
            'id' => (int)$book->id,
            'title' => strtoupper($book->title),
            'price' => '$' . $book->price,
            'published_at' => $book->published_at->format('d/m/Y'),
            'url' => 'https://store.books.com/books/' . $book->id
        ];
    }
}
 php
return api_response()
    ->item(['result`' => 'success'], null, null, false)
    ->withCookie(new \Symfony\Component\HttpFoundation\Cookie('name', 'value'))
    ->build();
 php
return api_response()
    ->item(['result`' => 'success'], null, null, false)
    ->withHeader('X-CUSTOM', 'customvalue')
    ->build();