PHPackages                             jayc89/slim-json-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. [Templating &amp; Views](/categories/templating)
4. /
5. jayc89/slim-json-api

ActiveLibrary[Templating &amp; Views](/categories/templating)

jayc89/slim-json-api
====================

Slim extension to implement fast JSON API's

1.2.0(11y ago)020GPL 3.0PHPPHP &gt;=5.3.0

Since May 17Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jayc89/slim-json-api)[ Packagist](https://packagist.org/packages/jayc89/slim-json-api)[ Docs](https://github.com/jayc8/slim-json-api)[ RSS](/packages/jayc89-slim-json-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

\#slim-jsonAPI [![Latest Stable Version](https://camo.githubusercontent.com/761a46ff25edf9e49e37d2cb5eba4338619108b54c74861fd8aaca07e00fb128/68747470733a2f2f706f7365722e707567782e6f72672f6a61796338392f736c696d2d6a736f6e2d6170692f762f737461626c652e706e67)](https://packagist.org/packages/jayc89/slim-json-api)[![Total Downloads](https://camo.githubusercontent.com/6a6a9f3e6370a7d3c9e2d639b18093c92f989a51c1669a406edfb0ba5ba6f780/68747470733a2f2f706f7365722e707567782e6f72672f6a61796338392f736c696d2d6a736f6e2d6170692f646f776e6c6f6164732e706e67)](https://packagist.org/packages/jayc89/slim-json-api)[![Bitdeli Badge](https://camo.githubusercontent.com/9d93fbb37ff112db9aa3908c86f3d25075096800a9298d99ec9367421b09f633/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f6a61796338392f736c696d2d6a736f6e2d6170692f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

This is an extension to the [SLIM framework](https://github.com/codeguy/Slim) to implement json API's with great ease.

\##Installation Using composer you can add use this as your composer.json

```
    {
        "require": {
            "slim/slim": "2.*",
            "jayc89/slim-json-api": "dev-master"
        }
    }
```

\##Usage To include the middleware and view you just have to load them using the default *Slim* way. Read more about Slim Here ()

```
    require 'vendor/autoload.php';

    $app = new \Slim\Slim();

    $app->view(new \JsonApiView());
    $app->add(new \JsonApiMiddleware());
```

\###.htaccess sample Here's an .htaccess sample for simple RESTful API's

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

\###example method all your requests will be returning a JSON output. the usage will be `$app->render( (int)$HTTP_CODE, (array)$DATA);`

\####example Code

```
    $app->get('/', function() use ($app) {
        $app->render(200,array(
                'msg' => 'welcome to my API!',
            ));
    });
```

\####example output

```
{
    "msg":"welcome to my API!",
    "error":false,
    "status":200
}
```

\##Errors To display an error just set the `error => true` in your data array. All requests will have an `error` param that defaults to false.

```
    $app->get('/user/:id', function($id) use ($app) {

        //your code here

        $app->render(404,array(
                'error' => TRUE,
                'msg'   => 'user not found',
            ));
    });
```

```
{
    "msg":"user not found",
    "error":true,
    "status":404
}
```

You can optionally throw exceptions, the middleware will catch all exceptions and display error mensages.

```
    $app->get('/user/:id', function($id) use ($app) {

        //your code here

        if(...){
            throw new Exception("Something wrong with your request!");
        }
    });
```

```
{
    "error": true,
    "msg": "ERROR: Something wrong with your request!",
    "status": 500
}
```

\##routing specific requests to the API If your site is using regular HTML responses and you just want to expose an API point on a specific route, you can use Slim router middlewares to define this.

```
    function APIrequest(){
        $app = \Slim\Slim::getInstance();
        $app->view(new \JsonApiView());
        $app->add(new \JsonApiMiddleware());
    }

    $app->get('/home',function() use($app){
        //regular html response
        $app->render("template.tpl");
    });

    $app->get('/api','APIrequest',function() use($app){
        //this request will have full json responses

        $app->render(200,array(
                'msg' => 'welcome to my API!',
            ));
    });
```

\##middleware The middleware will set some static routes for default requests. **if you dont want to use it**, you can copy its content code into your bootstrap file.

***IMPORTANT: remember to use `$app->config('debug', false);` or errors will still be printed in HTML***

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 76.1% 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 ~124 days

Total

6

Last Release

4118d ago

Major Versions

0.1 → 1.0.22013-09-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d11f2e76de7ba7b3ebe3df115f6e81842fb6b7f0896189c53f2116fd3f35e3c?d=identicon)[jayc89](/maintainers/jayc89)

---

Top Contributors

[![entomb](https://avatars.githubusercontent.com/u/57768?v=4)](https://github.com/entomb "entomb (35 commits)")[![martemorfosis](https://avatars.githubusercontent.com/u/2488715?v=4)](https://github.com/martemorfosis "martemorfosis (4 commits)")[![bignall](https://avatars.githubusercontent.com/u/1179454?v=4)](https://github.com/bignall "bignall (3 commits)")[![beamcode](https://avatars.githubusercontent.com/u/73224590?v=4)](https://github.com/beamcode "beamcode (1 commits)")[![baileylo](https://avatars.githubusercontent.com/u/145345?v=4)](https://github.com/baileylo "baileylo (1 commits)")[![Philzen](https://avatars.githubusercontent.com/u/1634615?v=4)](https://github.com/Philzen "Philzen (1 commits)")[![woolfg](https://avatars.githubusercontent.com/u/1328269?v=4)](https://github.com/woolfg "woolfg (1 commits)")

---

Tags

jsonmiddlewareapislimview

### Embed Badge

![Health badge](/badges/jayc89-slim-json-api/health.svg)

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

###  Alternatives

[entomb/slim-json-api

Slim extension to implement fast JSON API's

268156.4k4](/packages/entomb-slim-json-api)[dogancelik/slim-json

JSON middleware for Slim PHP framework

3984.0k3](/packages/dogancelik-slim-json)[infyomlabs/generator-builder

InfyOm Laravel Generator GUI Builder

132435.7k](/packages/infyomlabs-generator-builder)[shoot/shoot

Shoot aims to make providing data to your templates more manageable

41229.9k2](/packages/shoot-shoot)

PHPackages © 2026

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