Laravel REST API Response Builder

Laravel REST API Response Builder

REST API Response Builder for Laravel is a package by Marcin Orlowski for building JSON API responses. According to the author, the package helps you with things like data conversion and localization:

ResponseBuilder is written for REST API developers by REST API developer and is based on my long-lasting experience on both “sides” (API dev and API consumer) of a variety of REST APIs. Lightweight, with simple to use public methods, covering multiple potential use-cases, on-the-fly data conversion, localization support, automatic error message building, support for chained APIs, and (hopefully) exhaustive documentation.

The simplest example provided by this package is returning the following from a controller:

return ResponseBuilder::success();

The resulting client JSON will look like the following:

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

If you want to build message codes for common errors in your API, you can do the following:

return ResponseBuilder::error(MyErrorCodes::SOME_CODE);

Which results in the following message if you passed the code 205:

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

Check out the detailed documentation for more examples of what this package provides. You can learn more about this package, get full installation instructions, and view the source code on GitHub at MarcinOrlowski/laravel-api-response-builder.


Filed in: News / packages


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

PHP Data Engineer
Remote (US)
FBS
Software Developer
Remote (US & Canada)
Alley
Backend Software Engineer
Remote (UTC +/- 5)
Smartbnb
Programmer
Remote (Overlap w/ Continental US Time Zones)
Tighten
Senior Backend Engineer
Remote
64 Robots
Senior Laravel Developer
Atlanta, GA
Helium LLC
Full-Stack Developer (JS - Vue.js, PHP - Laravel)
US Remote / Telecommute
TTEC Digital