Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/firebit/laravel-api-response
Simple Laravel package for creating API responses, compliant with JSend and the HTTP standard.
https://github.com/firebit/laravel-api-response
api-rest http-status-code jsend laravel laravel-package
Last synced: 8 days ago
JSON representation
Simple Laravel package for creating API responses, compliant with JSend and the HTTP standard.
- Host: GitHub
- URL: https://github.com/firebit/laravel-api-response
- Owner: firebit
- License: mit
- Created: 2019-10-08T20:19:23.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-30T10:01:51.000Z (about 4 years ago)
- Last Synced: 2024-09-26T17:08:39.733Z (about 2 months ago)
- Topics: api-rest, http-status-code, jsend, laravel, laravel-package
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel API Response
This package aims to makes responses from the API consistent and easy to use. It is compliant with the HTTP standard and the JSend standard.## Example
#### Code
```php
function getUser($id){
// Get the data we wish to return
$user = User:find($id);
// If the user does not exist we return an error
if(!$user){
return ApiResponseFactory::notFound("User does not exist");
}
// Return the data by using a ReponseFactory
return ApiResponseFactory::success($user);
}
```#### Error output
```json
{
"status":"fail",
"message":"User does not exist"
}
```#### Success output
```json
{
"status":"success",
"data": {
"id":1,
"name":"John Doe",
"email":"[email protected]",
"created_at":null,
"updated_at":null
}
}
```## Installation
To install you can use Composer, use the following command to install this package.
`` composer require firebit/laravel-api-response``## Documentation
Coming soon!## Progress
- [X] JSend compliance
- [ ] PHPUnit tests
- [ ] Documentation## License
For the license please check the LICENSE file, this project has the MIT license.