PHPackages                             jenky/laravel-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jenky/laravel-api

ActiveLibrary[API Development](/categories/api)

jenky/laravel-api
=================

Laravel API

7.2.0(5y ago)2938MITPHPPHP ^7.2|^8.0

Since Dec 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jenky/laravel-api)[ Packagist](https://packagist.org/packages/jenky/laravel-api)[ Docs](https://github.com/jenky/laravel-api)[ RSS](/packages/jenky-laravel-api/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (5)Versions (50)Used By (0)

Laravel API
===========

[](#laravel-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/00e4c8c533cefe5479a1fe6ec210b1a0d480fc1ce26e60d53e2580b9ce9a3c37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a656e6b792f6c61726176656c2d6170692e737667)](https://packagist.org/packages/jenky/laravel-api)[![Test Status](https://github.com/jenky/laravel-api/workflows/Tests/badge.svg)](https://github.com/jenky/laravel-api/actions)[![Codecov](https://camo.githubusercontent.com/934fea7fe4c3c8ec58674884c1aca003151504a2d2191a823f03fe2326c87604/68747470733a2f2f636f6465636f762e696f2f67682f6a656e6b792f6c61726176656c2d6170692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/jenky/laravel-api)[![Total Downloads](https://camo.githubusercontent.com/47a35feb82f1e08043d8cb9141def5e6dbd3697ee5ec527ab199a21a9a0ada0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a656e6b792f6c61726176656c2d6170692e737667)](https://packagist.org/packages/jenky/laravel-api)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)

The package provides a nice and easy way to define API routes and format JSON error response.

- [Laravel API](#laravel-api)
    - [Install](#install)
    - [Installation](#installation)
    - [Configuration](#configuration)
    - [Usage](#usage)
        - [Error response](#error-response)
    - [Change log](#change-log)
    - [Testing](#testing)
    - [Contributing](#contributing)
    - [Security](#security)
    - [Credits](#credits)
    - [License](#license)

Install
-------

[](#install)

Installation
------------

[](#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
-------------

[](#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
-----

[](#usage)

### Error response

[](#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.

```
