dkx/slim-fractal-response

Return item or collection from Fractal easily

0.0.1 2019-05-21 14:02 UTC

This package is auto-updated.

Last update: 2022-07-21 22:14:49 UTC


README

Installation

$ composer require dkx/slim-fractal-response

Usage

Register middleware:

<?php

use DKX\SlimFractalResponse\FractalResponseMiddleware;

$app->add(new FractalResponseMiddleware($fractalManager));

Use in route:

<?php

use DKX\SlimFractalResponse\CollectionResponse;
use DKX\SlimFractalResponse\ItemResponse;
use Slim\Http\Request;
use Slim\Http\Response;

$app->get('/users', function (Request $request, Response $response): Response {
	return new CollectionResponse($response, $userTransformer, $users);
});

$app->get('/users/{id}', function (Request $request, Response $response): Response {
	return new ItemResponse($response, $userTransformer, $user);
});