jenky / laravel-api
Laravel API
Requires
- php: ^7.2|^8.0
- illuminate/config: ^7.0|^8.0
- illuminate/contracts: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
Suggests
- spatie/laravel-fractal: An easy to use Fractal wrapper built for Laravel applications.
- spatie/laravel-query-builder: Easily build Eloquent queries from API requests.
- 7.x-dev
- dev-master / 7.x-dev
- 7.2.0
- 7.1.4
- 7.1.3
- 7.1.2
- 7.1.1
- 7.1.0
- 7.0.0
- 6.x-dev
- 6.4.2
- 6.4.1
- 6.4.0
- 6.3.3
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.1
- 6.1.0
- 6.0.1
- 6.0.0
- 5.x-dev
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.x-dev
- 4.0.0
- 3.x-dev
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-exception
- dev-route-macro
This package is auto-updated.
Last update: 2024-11-21 01:39:30 UTC
README
The package provides a nice and easy way to define API routes and format JSON error response.
Install
Installation
You may use Composer to install this package into your Laravel project:
$ composer require jenky/laravel-api
After installing, publish its assets using the vendor:publish
Artisan command.
php artisan vendor:publish
or
php artisan vendor:publish --provider="Jenky\LaravelAPI\ApiServiceProvider"
Configuration
After publishing Laravel API's assets, its primary configuration file will be located at config/api.php
. This configuration file allows you to configure your api route and error response format and each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.
For Header versioning, if the request doesn't have the
Accept
header with correct format then default version from config will be used.
Usage
Error response
Dealing with errors when building an API can be a pain. Instead of manually building error responses you can simply throw an exception and the API will handle the response for you. Just add the trait ExceptionResponse
to your app/Exceptions/Handler
and the package will automatically catches the thrown exception and will convert it into its JSON representation.
<?php namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Jenky\LaravelAPI\Exception\ExceptionResponse; class Handler extends ExceptionHandler { use ExceptionResponse; }
You can change the default error response format in
config/api.php
file.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email contact@lynh.me instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.