PHPackages                             isaackearl/artisan-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. isaackearl/artisan-api

AbandonedArchivedLibrary[API Development](/categories/api)

isaackearl/artisan-api
======================

An api service for Laravel or Lumen. Helps you send responses with the proper status and code. Uses Fractal for items and collections.

v1.0.2(8y ago)337MITPHPPHP ~5.6|~7.0

Since Aug 9Pushed 7y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (11)Versions (6)Used By (0)

Artisan API
===========

[](#artisan-api)

[![Latest Stable Version](https://camo.githubusercontent.com/66d6892bea902ba149a05ceb3dccd8262dc412eff8f2e1d48da7bc583d1291b9/68747470733a2f2f706f7365722e707567782e6f72672f69736161636b6561726c2f6172746973616e2d6170692f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/isaackearl/artisan-api)[![Latest Unstable Version](https://camo.githubusercontent.com/d3cff1ad64fc9fc038342ab03d16f3e9b5e07067ac3dbc8209dfd449d72e1a7d/68747470733a2f2f706f7365722e707567782e6f72672f69736161636b6561726c2f6172746973616e2d6170692f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/isaackearl/artisan-api)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/4a1cb1f5d35fac11a0252a954520ef8abf788d7e528865a280ff3de0fe17c7e8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f69736161636b6561726c2f6172746973616e2d6170692f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/isaackearl/artisan-api)[![Coverage Status](https://camo.githubusercontent.com/c07ba7e88566c28b05b9e123d28ea96f4f5dac0e7426ac7c9382956bdb207ec4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f69736161636b6561726c2f6172746973616e2d6170692f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/isaackearl/artisan-api?branch=master)[![Total Downloads](https://camo.githubusercontent.com/b964e38ac5ce8e2a0aa8d64c5444edd00d94917825143f6255d54dc99d39a672/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69736161636b6561726c2f6172746973616e2d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isaackearl/artisan-api)

An api service for Laravel or Lumen. Helps you send responses with the proper status and code. Uses Fractal for items and collections.

Setup/Install
-------------

[](#setupinstall)

Require it with Composer

```
$ composer require isaackearl/artisan-api
```

Add the service provider to config/app.php

```
// For Laravel add this to config/app.php
IsaacKenEarl\LaravelApi\Providers\ArtisanApiServiceProvider::class

// For Lumen add this to bootstrap/app.php
$app->register(IsaacKenEarl\LaravelApi\Providers\ArtisanApiServiceProvider::class);
```

(Optional) Add the API facade in config/app.php

```
'Api' => IsaacKenEarl\LaravelApi\Facades\Api::class,
```

Usage
-----

[](#usage)

In your controllers you can do stuff like this:

```
// do stuff like this
public function show() {
    return Api::respondWithItem($user, new UserTransformer());
}

// or like this:

return Api::respondNotFound();
```

There are alot of options. Include the ArtisanApiInterface in your controller constructor and you can use it without the facade.

```
    private $api;

    public function __construct(ArtisanApiServiceInterface $apiService)
    {
        $this->api = $apiService;
    }

    public function index()
    {
        $users = User::all();
        return $this->api->respondWithCollection($users, new UserTransformer());
    }
```

You can do custom stuff too and chain methods

```
// you can respondWithError or respondWithMessage and customize the status code
// and response code etc
return $this->api
            ->setStatus(401)
            ->setResponseCode(ResponseCodes::UNAUTHORIZED)
            ->respondWithError('Not logged in');
```

Take a look at the ArtisanApiInterface to see all the supported methods. You can find that here:

[ArtisanApiInterface](https://github.com/isaackearl/artisan-api/blob/master/src/Interfaces/ArtisanApiServiceInterface.php)

Transformers
------------

[](#transformers)

Transformers allow you to control how the data is presented in the response of your API. A typical transformer looks like this:

```
class UserTransformer extends Transformer
{
    function transform($user)
    {

        return [
            'id' => $user->id,
            'name' => $user->name,
            'date_of_birth' => $user->date_of_birth->toDateString(),
            'email' => $user->getPrimaryEmail()
        ];
    }
}
```

You can generate a transformer with the make:transformer command

```
php artisan make:transformer UserTransformer
```

This package uses [laravel-fractal](https://github.com/spatie/laravel-fractal) as it's fractal implementation. Check out their docs on their github page for more specific usage information and examples.

Since we are using the laravel-fractal package you can also publish the [laravel-fractal](https://github.com/spatie/laravel-fractal) config to customize the response data.

```
php artisan vendor:publish --provider="Spatie\Fractal\FractalServiceProvider"
```

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Credits
-------

[](#credits)

- [Isaac Earl](https://github.com/isaackearl)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3195d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bc94f4bdaff45c6215359fc183075dd9b5abfeb73758d3f2acda5b4bb490341?d=identicon)[isaackearl](/maintainers/isaackearl)

---

Top Contributors

[![isaackearl](https://avatars.githubusercontent.com/u/9354830?v=4)](https://github.com/isaackearl "isaackearl (33 commits)")

---

Tags

apilaravellumenartisanlaravel-apiIsaacKenEarlartisan apiisaackearl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/isaackearl-artisan-api/health.svg)

```
[![Health](https://phpackages.com/badges/isaackearl-artisan-api/health.svg)](https://phpackages.com/packages/isaackearl-artisan-api)
```

###  Alternatives

[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[api-ecosystem-for-laravel/dingo-api

A RESTful API package for the Laravel and Lumen frameworks.

3121.5M10](/packages/api-ecosystem-for-laravel-dingo-api)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2113.6k](/packages/wayofdev-laravel-symfony-serializer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
