gbdematos's avatar

API with Fractal - Where should logic go?

Hi!

I'm building an API using Fractal, and my main question (at the moment) is: Where should the logic for includes go?

Following Fractal's example:

public function includeAuthor(Book $book)
    {
        $author = $book->author;
        return $this->item($author, new AuthorTransformer);
    }

This logic is simple and contained in the BookTransformer, but what if I have a more complex logic to fetch the items to include? For example, if I want to include all the authors, or the most popular ones, or the main ones? This kind of logic that determine which items should be included...

And what if I want to paginate this authors? With a collection of books with authors included, this would be a mess of pagination (only to save additional http requests)?

Any help would be really appreciated! Thanks!

0 likes
1 reply

Please or to participate in this conversation.