MarcinOrlowski / laravel-api-response-builder by MarcinOrlowski

Helps building nice, normalized and easy to consume Laravel REST API.
63,435
446
15
Package Data
Maintainer Username: MarcinOrlowski
Package Create Date: 2016-04-11
Package Last Update: 2021-04-21
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2021-04-29 15:19:41
Package Statistics
Total Downloads: 63,435
Monthly Downloads: 4,026
Daily Downloads: 168
Total Stars: 446
Total Watchers: 15
Total Forks: 51
Total Open Issues: 0

API Response Builder for Laravel 5.x

Latest Stable Version Build Status Codacy Grade Badge Monthly Downloads License Dependency Status

SensioLabsInsight

Latest Unstable Version Build Status

Table of contents

Upgrading from previous version? Ensure you read compatibility docs prior altering your composer.json!


Introduction

ResponseBuilder is Laravel's helper designed to simplify building nice, normalized and easy to consume REST API responses.

Conclude your controller method with simple

return ResponseBuilder::success();

and your client will get nice JSON like

{
  "success": true,
  "code": 0,
  "locale": "en",
  "message": "OK",
  "data": null
}

Something went wrong? Just do

return ResponseBuilder::error(250);

and the following JSON response will be returned

{
   "success": false,
   "code": 250,
   "locale": "en",
   "message": "Your error message for code 250",
   "data": null
}

Nice and easy! And yes, message can be easily customized! Also there're much, much more you can do with rich ResponseBuilder's API. See library documentation for details and usage examples!


Features

  • Easy to use,
  • Stable and production ready,
  • Laravel 5.1 to 5.8 compatible,
  • Supports Laravel auto-discovery (5.5 and up),
  • Works on PHP 5.5, 5.6, 7.0, 7.1, 7.2 and 7.3,
  • Configurable (with ready-to-use defaults),
  • Localization support,
  • Automatic object conversion with custom mapping,
  • API chaining/cascading support,
  • Includes traits to help unit testing your API code,
  • Provides own exception handler helper to ensure your API stays consumable even in case of unexpected,
  • No extra dependencies.

Contributing

Please report any issue spotted using GitHub's project tracker.

If you'd like to contribute to the this project, please open new ticket before doing any work. This will help us save your time in case I'd not be accept PR either completely or in proposed form. But if all is good and clear then follow common routine:

  • fork the project,
  • create new branch,
  • do your changes,
  • add tests covering your changes,
  • ensure ALL tests pass,
  • send pull request,
  • glory.

License

  • Written and copyrighted ©2016-2019 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
  • ResponseBuilder is open-sourced software licensed under the MIT license