Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

api-response

> 编程语言
Open source

Simple package to handle response properly in your API.

372 stars0 likes2 views
WebsiteGitHub

About

Simple package to handle response properly in your API.

api-response

Simple package to handle response properly in your API. This package uses Fractal and is based on Build APIs You Won't Hate book.

Install

Via Composer

bash
$ composer require ellipsesynergie/api-response

Requirements

Version Branch PHP Laravel
2.x master 8.3 - 8.5 11 - 13
1.x 1.x 8.1 - 8.3 8 - 10

Version 2.x removed Lumen support, since Lumen is no longer maintained. If you need Lumen, stay on 1.x.

Install in Laravel

The service provider is auto-discovered. If you have disabled package discovery, add this following service provider to your config/app.php file.

php
EllipseSynergie\ApiResponse\Laravel\ResponseServiceProvider::class

Install in your favorite framework or vanilla php

This package can be used in any framework or vanilla php. You simply need to extend EllipseSynergie\ApiResponse\AbstractResponse and implement the withArray() method in your custom class. You can take a look at EllipseSynergie\ApiResponse\Laravel\Response::withArray() for an example.

You will also need to instantiate the response class with a fractal manager instance.

php
// Instantiate the fractal manager
$manager = new \League\Fractal\Manager;

// Set the request scope if you need embed data
$manager->parseIncludes(explode(',', $_GET['include']));

// Instantiate the response object, replace the class name by your custom class
$response = new \EllipseSynergie\ApiResponse\AbstractResponse($manager);

For more options related to the fractal manager, you can take a look at the official Fractal website

Example inside Laravel controller

…

Ouput example

One book

json
{
    "data": {
        "id": 1,
        "title": "My name is Bob!.",
        "created_at": {
            "date": "2014-03-25 18:54:18",
            "timezone_type": 3,
            "timezone": "UTC"
        },
        "updated_at": {
            "date": "2014-03-25 18:54:18",
            "timezone_type": 3,
            "timezone": "UTC"
        },
        "deleted_at": null
    }
}

Collection of books

…

Error

json
{
    "error": {
        "code": "GEN-NOT-FOUND",
        "http_code": 404,
        "message": "Book Not Found"
    }
}

Testing the package

bash
$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

  • Maxime Beaudoin
  • Phil Sturgeon
  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言