GitHub - MarcinOrlowski/laravel-api-response-builder: Builds nice, normalized an...
source link: https://github.com/MarcinOrlowski/laravel-api-response-builder
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
REST API Response Builder for Laravel
Table of contents
- Introduction
- Why should I use it?
- Usage examples
- Features
- Documentation
- Requirements
- Installation and Configuration
- Bugs reports and pull requests
- License
- Changelog
Upgrading from previous version? Ensure you read compatibility docs prior altering your composer.json
!
Introduction
ResponseBuilder
is Laravel's helper designed to build nice, normalized and easy to consume REST API
JSON responses.
Benefits
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 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. But that's not all! The JSON structure produced by ResponseBuilder
is designed with users of your API in mind, which helps them easily deal with your API with ease. They get simple, well
defined and predictable JSON structure responses with all the fields needed to consume it without any unnecessary a hassle nor
other trickery.
Android developers can use ApiResponse library to handle ResponseBuilder
responses produced in their mobile applications.
You are even covered in case of emergency as provided Exception Handler ensures your API keeps talking JSON (and not HTML) to its clients if case of any unexpected and unhandled exception.
Did I mention, you also get testing traits that would automatically cover your whole ResponseBuilder
related code with
unit tests with just a few lines of code?
Usage examples
Operation successful? Conclude your controller method with:
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
API. See library documentation for details and more examples!
Features
- Easy to use,
- Stable and production ready,
- Laravel compatibility: v6.x (see legacy support if you use older Laravel version),
- Supports Laravel auto-discovery,
- Configurable (with ready-to-use defaults),
- Localization support,
- Automatic object conversion with custom mapping,
- API chaining/cascading support,
- Includes traits to help unit test your API code,
- Provides own exception handler helper to ensure your API stays consumable even in case of unexpected,
- No extra dependencies.
License
- Written and copyrighted ©2016-2019 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
- ResponseBuilder is open-sourced software licensed under the MIT license
Recommend
-
15
README.md Newscatcher Programmatically collect normalized news from (almost) any website. By newscat...
-
21
Newscatcher Programmatically collect normalized news from (almost) any website. Filter by topic , country , or language . By
-
4
Who Builds the Builder? Aug 12, 2020 This is a short note on the builder pattern, or, rather, on the builder method pattern. TL;DR: if you have Foo and FooBuilder
-
4
September 1, 2015 Designing Normalized SQL Tables SQL databases are reliable for complex queries, partial updates, transactions, and decoupling da...
-
4
1. RepressionSometimes we pretend that self-repression is a thing of the past. Many old social taboos are gone, but that doesn’t always mean we understand ourselves well.For example, take the fear of...
-
4
(Gigerenzer & Hoffrage). Natural frequencies, chances, normalized... Figure 1 - uploaded by Steven A. SlomanContent may be subject to co...
-
3
Bankrupt PC builder Artesian Builds is auctioning off almost $1 million worth of stock Soon after that controversial raffle livestream By
-
2
TechJPMorgan says Apple's Mac supply has normalized
-
2
Risky Online Behaviour Such as Piracy 'Almost Normalized' Among Young People, Says Study ...
-
6
Faster CI builds for Rust with pre-baked builder images and sccache
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK