2017 © Pedro Peláez
 

library api-response-creator

Package to give common exit point to handle api responses with multiple error codes.

image

swapnil/api-response-creator

Package to give common exit point to handle api responses with multiple error codes.

  • Saturday, May 28, 2016
  • by swapnilgeek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

ApiResponse

Maintained by @anshdesire, Laravel api reponse generatorin the laravel 5 application. and published to packagist(https://packagist.org/packages/swapnil/api-response-creator) ., (*1)

Installation

You can install the package through Composer., (*2)

composer require swapnil/api-response-creator, (*3)

You must install this service provider. Make this the very first provider in list.

```php

'providers' => [
    'Swapnil\ApiResponse\ServiceProvider',
    //...
];

Publish

php artisan vendor:publish, (*4)

Use


return \ApiResponse::respond($data, $status = true,$headers = []); return \ApiResponse::setStatusCode(200); return \ApiResponse::setErrorCode(200); //with error code given in cofig. return \ApiResponse::getStatusCode(); return \ApiResponse::getStatusCodeList()[404]; return \ApiResponse::respondWithPagination(Paginator $items, $data, $status= true); // if pagination data needs to be send then Method chaining can also be used here. return \ApiResponse::setStatusCode(200)->ApiResponse::respondWithPagination(Paginator $items, $data, $status= true); Standard json response structure { "status_code": 422, "errors": [ { "error_message": "Validation error.", "error_code": 2004, "error_data": { "user_name": [ "The user name has already been taken." ], "mobile": [ "The mobile has already been taken." ] } } ], "data": [], "paginator": [], "success": false, "success_message": "Unprocessed entity" } All kind of error codes and error messages can be configured in swapnil.api-response.php config file. 'status_code' => 200, 'status_code_list' => [ 200 => 200, 422 => 422, 201 => 201, 404 => 404, 500 => 500, ], 'status_code_messages' => [ 200 => 'Request successfully processed.', 422 => 'Unprocessed entity', 201 => 'Created.', 404 => '', 500 => 'Internal Server Error.', ], 'errors_list' => [ // configurable '2001' => [ 'error_message' => 'User not found or wrong credentials.', 'error_code' => 2001, 'error_data' => '', ], '2002' => [ 'error_message' => '2002', 'error_code' => 2002, 'error_data' => '', ], '2003' => [ 'error_message' => 'Unable to create.', 'error_code' => 2003, 'error_data' => '', ], '2004' => [ 'error_message' => 'Validation error.', 'error_code' => 2004, 'error_data' => '', ] ],

License

The MIT License (MIT). Please see LICENSE for more information., (*5)

The Versions

28/05 2016

dev-master

9999999-dev

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses

01/05 2016

v1.00.04

1.00.04.0

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses

21/04 2016

v1.00.03

1.00.03.0

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses

20/04 2016

v1.00.02

1.00.02.0

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses

19/04 2016

v1.00.01

1.00.01.0

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses

19/04 2016

v1.0

1.0.0.0

Package to give common exit point to handle api responses with multiple error codes.

  Sources   Download

MIT

The Requires

 

by Swapnil Tripathi

api responses