tattran22/response

There is no license information available for the latest version (2.0.4) of this package.

Easy API Response Transformation for Laravel

2.0.4 2024-03-28 08:14 UTC

This package is auto-updated.

Last update: 2024-04-28 08:28:33 UTC


README

This Laravel package simplifies handling API responses using the Fractal library. It lets you easily:

  • Transform data: Convert raw data into structured responses.
  • Include relationships: Add related data to your responses without separate requests.
  • Handle pagination: Automatically add pagination links and metadata.

Installation

Just run this command in your terminal:

composer require tattran22/response

Usage

  1. Prepare your data: Use Eloquent models, arrays, or any suitable format.
  2. Create a transformer: Define how to transform your data using a ResponseTransformer class.
  3. Transform your data: Call transformData with your data and transformer.
    use TatTran\Response\Transformers\ResponseTransformer;
    
    $transformer = new ResponseTransformer($manager);
    $response = $transformer->transformData($data, $transformerInstance);
  4. (Optional) Include relationships: Add include parameters to your API requests (e.g., ?include=relationship).
    $transformer->setIncludes(['include1', 'include2']);

Features

  • Easy transformation: Define transformations in clear, readable code.
  • Includes parsing: Automatically handle include query parameters.
  • Pagination support: Add pagination links and metadata seamlessly.
  • Set includes programmatically: Control included relationships in code.

Open Source & Credits

This package is free to use under the MIT license and developed by Tat Tran.