|
2 | 2 |
|
3 | 3 | # REST API Response Builder for Laravel # |
4 | 4 |
|
5 | | - `ResponseBuilder` is [Laravel](https://laravel.com/)'s helper designed to simplify building |
6 | | - nice, normalized and easy to consume REST API responses. |
| 5 | + `ResponseBuilder` is [Laravel](https://laravel.com/)'s helper designed to build |
| 6 | + nice, normalized and easy to consume REST API JSON responses. |
7 | 7 |
|
8 | 8 | ## Table of contents ## |
9 | 9 |
|
|
26 | 26 | ## Response structure ## |
27 | 27 |
|
28 | 28 | Predictability, simplicity and no special-case is the key of the `ResponseBuilder` design. I wanted to make my life easier not |
29 | | - only when I develop the API itself, but also when I'd try to use it i.e. in mobile applicationsm, therefore response created with |
30 | | - this package **guarantees** consisten JSON structure. |
| 29 | + only when I develop the API itself, but also when I'd try to use it i.e. in mobile applications, therefore all responses created |
| 30 | + by this package **guarantee** consistent JSON structure by design. |
31 | 31 |
|
32 | | - Default response will always contains at least the following elements: |
| 32 | + By default response always contain at least the following elements: |
33 | 33 |
|
34 | 34 | ```json |
35 | 35 | { |
|
49 | 49 | * `message` (**string**) human readable message that is ready to display and explains human readable explanation of the `code` value, |
50 | 50 | * `data` (**object**|**array**|**null**) if you return any additional data with your reply, it would end here. If no extra data is needed, that key still be present in the response with `null` value. |
51 | 51 |
|
52 | | - **NOTE:** If you need to return other/different elements in the aboive structure (not in your `data`), see [Manipulating Response Object](#manipulating-response-object) chapter for detailed information about how to achieve this. |
| 52 | + **NOTE:** If you need to return other/different elements in the above structure (not in your `data`), see [Manipulating Response Object](#manipulating-response-object) chapter for detailed information about how to achieve this. |
53 | 53 |
|
54 | 54 | ---- |
55 | 55 |
|
@@ -237,7 +237,7 @@ return ResponseBuilder::errorWithMessage(ApiCodeBase::SOMETHING_WENT_WRONG, $msg |
237 | 237 | API invocations in the way that in case of problems (and cascading failure) I still would able to tell which one failed first. |
238 | 238 | For example our API client app calls method of publicly exposed API "A". That API "A" internally calls method of completely |
239 | 239 | different and separate API "B". Under the hood API "B" delegates some work and talks to API "C". When something go wrong and |
240 | | - "C"'s metod fail, client shall see "C"'s error code and error message, not the "A"'s. To acheive this each API you chain return |
| 240 | + "C"'s method fail, client shall see "C"'s error code and error message, not the "A"'s. To achieve this each API you chain return |
241 | 241 | unique error codes and the values are unique per whole chain To support that `ResponseBuilder` features code ranges, allowing |
242 | 242 | you to configure `min_code` and `max_code` you want to be allowed to use in given API. `ResponseBuilder` will ensure no values not |
243 | 243 | from that range is ever returned, so to make the whole chain "clear", you only need to properly assign non-overlapping ranges to |
@@ -389,8 +389,8 @@ return ResponseBuilder::success($flights); |
389 | 389 | ], |
390 | 390 | ``` |
391 | 391 |
|
392 | | - The above confgures two classes (`Model` and `Collection`). Whenver object of that class is spotted, method specified in `method` |
393 | | - key would be called on that obhject and data that method returns will be returned in JSON object using key specidied in `key`. |
| 392 | + The above configures two classes (`Model` and `Collection`). Whenever object of that class is spotted, method specified in `method` |
| 393 | + key would be called on that object and data that method returns will be returned in JSON object using key specified in `key`. |
394 | 394 |
|
395 | 395 | So in above example, if we get `Collection`, then `ResponseBuilder` would call `toArray()` on it, and result data would |
396 | 396 | be added in returned JSON in `items` object. |
@@ -649,5 +649,5 @@ MarcinOrlowski\ResponseBuilder\BaseApiCodes::NO_ERROR_MESSAGE() => 'my_messages. |
649 | 649 |
|
650 | 650 | ## License ## |
651 | 651 |
|
652 | | - * Written and copyrighted ©2016-2019 by Marcin Orlowski <mail (#) marcinorlowski (.) com> |
| 652 | + * Written and copyrighted ©2016-2019 by Marcin Orlowski <mail (#) marcinOrlowski (.) com> |
653 | 653 | * ResponseBuilder is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) |
0 commit comments