PHPackages                             swisnl/json-api-server - 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. swisnl/json-api-server

Abandoned → [laravel-json-api/laravel](/?search=laravel-json-api%2Flaravel)ArchivedLibrary[API Development](/categories/api)

swisnl/json-api-server
======================

Set up a JSON API in Laravel in just a few minutes.

0.6.0(3y ago)10515.8k20[5 issues](https://github.com/swisnl/json-api-server/issues)MITPHPPHP &gt;=7.2|^8.0

Since Feb 9Pushed 3y ago14 watchersCompare

[ Source](https://github.com/swisnl/json-api-server)[ Packagist](https://packagist.org/packages/swisnl/json-api-server)[ Docs](http://www.swis.nl)[ RSS](/packages/swisnl-json-api-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (20)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9fce270c02dcc2e1471a114bce899c69078e88d3dfc44afd494870f3e3e1627f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6a736f6e2d6170692d7365727665722e737667)](https://packagist.org/packages/swisnl/json-api-server)[![Build Status](https://camo.githubusercontent.com/7261b40afe3d72b7f31e93636e5fd898d891676a46864ef140e1d0d863c2cf1e/68747470733a2f2f7472617669732d63692e6f72672f737769736e6c2f6a736f6e2d6170692d7365727665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/swisnl/json-api-server)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://choosealicense.com/licenses/mit/)[![Made by SWIS](https://camo.githubusercontent.com/8c541545402619860a7346c32a176d63a2b75eb8ebb85590d06a26b62417d260/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e737667)](https://www.swis.nl)

🚨 **THIS PACKAGE HAS BEEN ABANDONED** 🚨

We don't use this package anymore in our own projects and there are many, better alternatives, so that's why we have chosen to abandon it. We suggest using [laravel-json-api/laravel](https://laraveljsonapi.io/) or one of the [other alternatives](https://jsonapi.org/implementations/#server-libraries-php) instead. Feel free to fork our code and maintain your own copy.

Laravel JSON API server
=======================

[](#laravel-json-api-server)

Set up a laravel API in just a few minutes with this package. All the standard API functionality is already there for you.

This package strives to save you some time while building your API. It already has the basic features an API should have, like:

- Generators to generate your needed files for each model
- An abstract layer to handle your basic CRUD actions
- Creates routes for all your endpoints
- Support for a few useful URL parameters
- Permission and route permission handling
- Responses in json api format ()
- Automatically translates your models based on your database

Install
-------

[](#install)

Via Composer

```
$ composer require swisnl/json-api-server
```

### Sample

[](#sample)

Please see the folder [sample](sample) for a sample of an application using this package.

Usage
-----

[](#usage)

### Base Api Classes

[](#base-api-classes)

There are a few base classes your classes should/could inherit:

#### BaseApiController

[](#baseapicontroller)

This controller handles your basic CRUD actions as well as permissions if you choose to use permissions.

#### BaseApiRepository

[](#baseapirepository)

This repository is a standard base repository with a small addition that it figures out your models relationships.

If you want to use your own BaseRepository, you have to implement the RepositoryInterface. This ensures that you have full compatibility with the BaseApiController.

The BaseApiRepository uses a trait to retrieve a models relationships. You can use this trait if you want to use the existing implementation.

### Generating the required files

[](#generating-the-required-files)

After installing the package you can instantly generate all the required files by executing this command:

```
$ php artisan json-api-server:generate-all {Model}
```

To override the default path without overriding the laravel\_generator config file, you can use the `--path={path}` option. For example:

```
$ php artisan json-api-server:generate-all Test --path=app/temp/
```

This generates the following files:

- An eloquent model
- A translation model
- An API controller
    - Should extend the BaseApiController
- A routes file where the all the CRUD endpoints are defined
- A repository for your model
    - Could extend the BaseApiRepository
- A policy for checking permissions
- 1 test for checking if a user has permissions for the endpoint

You'll be able to do the basic CRUD actions without writing anything.

You also have the ability to generate the files separately:

```
$ php artisan json-api-server:generate-controller {name}
$ php artisan json-api-server:generate-model {name}
$ php artisan json-api-server:generate-model-permissions {name}
$ php artisan json-api-server:generate-policy {name}
$ php artisan json-api-server:generate-repository {name}
$ php artisan json-api-server:generate-routes {name}
$ php artisan json-api-server:generate-test {name}
$ php artisan json-api-server:generate-translation {name}
```

### Configuration

[](#configuration)

If you would like to override the configuration files.

```
$ php artisan vendor:publish --tag=laravel-api
$ php artisan vendor:publish --tag=laravel-api-templates
```

If you decide to override the templates, make sure you override the laravel api config too. You have to define where your own templates are in the config.

This is the default configuration:

```
   return [
     // Generator configuration
     'path' => [
         'model' => app_path('/'),

         'model_permissions' => app_path('Permissions/'),

         'translation' => app_path('Translations/'),

         'controller' => app_path('Http/Controllers/Api/'),

         'repository' => app_path('Repositories/'),

         'policy' => app_path('Policies/'),

         'auth_test' => base_path('tests/Authentication/'),

         'templates' => 'vendor/swisnl/laravel-api/resources/templates/',

         'routes' => app_path('Http/Routes/')
     ],

     'namespace' => [
         'model' => 'App',

         'model_permissions' => 'App\Permissions',

         'controller' => 'App\Http\Controllers\Api',

         'repository' => 'App\Repositories',

         'translation' => 'App\Translations',

         'policy' => 'App\Policies',

         'auth_test' => 'App\Tests\Authentication'
     ],

     // Permissions configuration
     'permissions' => [
         'checkDefaultIndexPermission' => false,

         'checkDefaultShowPermission' => false,

         'checkDefaultCreatePermission' => false,

         'checkDefaultUpdatePermission' => false,

         'checkDefaultDeletePermission' => false,
     ],

     // Load all relationships to have response exactly like json api. This slows down the API immensely.
     'loadAllJsonApiRelationships' => true,
];
```

### Requests and responses

[](#requests-and-responses)

All requests and responses are formatted according to the format specified by .

There are several respond methods at your disposal in your controller. The following respond methods are implemented at this moment:

```
return $this->respondWithOk($object);
return $this->respondWithPartialContent($object);
return $this->respondWithCreated($object);
return $this->respondWithNoContent($object);
return $this->respondWithCollection($object);
```

These methods automatically converts your objects to json api format and creates a response with the correct status code and body.

### Using policies

[](#using-policies)

If you decide to use policies to check for the user's pemissions you have to add the policies to your Providers\\AuthServiceProvider.

```
 protected $policies = [
     Sample::class => SamplePolicy::class,
 ];

 public function boot()
 {
     $this->registerPolicies();
 }
```

The policies are preconfigured to work with Laravel passport, if you want to use another form of authorizing actions you can change the methods.

If you want to redirect the validation to a specific function in your policy.

```
$this->authorizeAction('show');
```

If you want to check if they can request a specific object you can add that object as the second parameter:

```
$this->authorizeAction('show', $requestedObject);
```

### URL parameters out of the box

[](#url-parameters-out-of-the-box)

The following URL parameters are supported after installing this package:

- ?include={relationship}: To add all relationship data to the response.
- ?page={pageNumber}: To decide which page the pagination should show.
- ?per\_page={amountToShowPerPage}:To decide how many items you get per page.
- ?ids={commaSeperatedIds}: To retrieve a collection of objects belonging to the ids.
- ?exclude\_ids={commaSeperatedIds}: To retrieve a collection of objects not belonging to the ids.
- ?lang={language}: (Requires the configure-locale middleware) to change the php locale to the desired language and automatically translates all translatable models.
- ?fields={columns}: To retrieve certain columns.
- ?order\_by\_desc={column}: To order descending based on a column.
- ?order\_by\_asc={column}: To order ascending based on a column.

### Mandatory middleware

[](#mandatory-middleware)

- inspect\_content\_type: Required. It ensures that the requests should be in json format. If it's in another format it throws a ContentTypeNotSupportedException.

### Optional middleware

[](#optional-middleware)

There is optional middleware:

- configure-locale: used to configure the language for translating your responses. Also configurable by using the URL paramater ?lang={language}

Passport installation
---------------------

[](#passport-installation)

**Note: if you want to know more about laravel passport and why these commands should be run go to **

```
$ composer require laravel/passport
$ php artisan migrate
$ php artisan passport:install
```

After running this command, add the `Laravel\Passport\HasApiTokens` trait to your `App\User` model

Next, you should call the `Passport::routes` method within the boot method of your `AuthServiceProvider`.

Finally, in your `config/auth.php` configuration file, you should set the driver option of the api authentication guard to passport. This will instruct your application to use Passport's TokenGuard when authenticating incoming API requests.

If you created your own routes make sure you have the `auth:api` middlware on all the routes you want to use passport with.

Packages Laravel-Api uses
-------------------------

[](#packages-laravel-api-uses)

##### Laravel framework

[](#laravel-framework)

-

##### Astrotomic / laravel-translatable

[](#astrotomic--laravel-translatable)

-

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Dylan de Wit](https://github.com/DylandeWit)

License
-------

[](#license)

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

SWIS
----

[](#swis)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 75.4% 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 ~130 days

Recently: every ~377 days

Total

15

Last Release

1196d ago

PHP version history (4 changes)0.1PHP ^7.0

0.4.0PHP &gt;=7.1.3

0.5.0PHP &gt;=7.2

0.6.0PHP &gt;=7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

---

Top Contributors

[![bbrala](https://avatars.githubusercontent.com/u/3294970?v=4)](https://github.com/bbrala "bbrala (52 commits)")[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (10 commits)")[![liepumartins](https://avatars.githubusercontent.com/u/2070205?v=4)](https://github.com/liepumartins "liepumartins (4 commits)")[![bondas83](https://avatars.githubusercontent.com/u/29758515?v=4)](https://github.com/bondas83 "bondas83 (3 commits)")

---

Tags

laravelJSON-APIswisnllaravel-apijson-api-server

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/swisnl-json-api-server/health.svg)

```
[![Health](https://phpackages.com/badges/swisnl-json-api-server/health.svg)](https://phpackages.com/packages/swisnl-json-api-server)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[cloudcreativity/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

7881.1M5](/packages/cloudcreativity-laravel-json-api)[laravel-json-api/laravel

JSON:API for Laravel applications.

6371.4M15](/packages/laravel-json-api-laravel)[timacdonald/json-api

A Lightweight JSON:API Resource for Laravel

639892.5k2](/packages/timacdonald-json-api)[specialtactics/laravel-api-boilerplate

An API boilerplate for Laravel

5451.5k](/packages/specialtactics-laravel-api-boilerplate)[swisnl/openapi-spec-generator

Creates Open API spec for a Laravel JSON:API

2338.1k](/packages/swisnl-openapi-spec-generator)

PHPackages © 2026

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