Download the PHP package dees040/laravel-api-responses without Composer
On this page you can find all versions of the php package dees040/laravel-api-responses. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dees040/laravel-api-responses
More information about dees040/laravel-api-responses
Files in dees040/laravel-api-responses
Package laravel-api-responses
Short Description Helper methods for Laravel API Responses
License MIT
Informations about the package laravel-api-responses
Laravel API Responses
A very small package which helps you to easily returning readable API responses.
Installation
Install the package via Composer.
You're ready to go!
Usage
Just use one of the helper functions and you're good to go.
Methods
All methods accept a $data
parameter. This can be any data which can be used in a JSON response, such as strings, integers, arrays, models, etc..
Method | Status Code |
---|---|
ok($data) |
200 |
created($data) |
201 |
accepted($data) |
202 |
no_content() |
204 |
bad_request($message, $errors) |
400 |
unauthenticated($message, $errors) |
401 |
forbidden($message, $errors) |
403 |
not_found($message, $errors) |
404 |
method_not_allowed($message, $errors) |
405 |
not_acceptable($message, $errors) |
406 |
teapot($message, $errors) |
418 |
unprocessable_entity($message, $errors) |
422 |
Custom response (code)
If you'd wish to send a status code which is not in the list you could use the json_response($data = null, $status = 200)
helper function. Here you can find a cheat sheet for HTTP status codes or use my personal favorite http.cat 😉.
If you want to send error response you can use the error_json_response($message = '', $errors = [], $status = 400)
. This method will send an json response like this:
Output:
All versions of laravel-api-responses with dependencies
illuminate/routing Version ~5.0|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0