PHPackages                             alesanchezr/slim-api-wrapper - 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. alesanchezr/slim-api-wrapper

ActiveLibrary[API Development](/categories/api)

alesanchezr/slim-api-wrapper
============================

Build Slim API's really fast

0.0.4(7y ago)0470PHPPHP &gt;=5.3.3

Since Apr 9Pushed 7y ago2 watchersCompare

[ Source](https://github.com/alesanchezr/slim-api-wrapper)[ Packagist](https://packagist.org/packages/alesanchezr/slim-api-wrapper)[ RSS](/packages/alesanchezr-slim-api-wrapper/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Slim On Steroids
================

[](#slim-on-steroids)

[![Build Status](https://camo.githubusercontent.com/24a17a2979d8169d99734d6a55ddc19c71fa6ecd85bee3e06a7bf4732f38010a/68747470733a2f2f7472617669732d63692e6f72672f616c6573616e6368657a722f736c696d2d6170692d777261707065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alesanchezr/json-orm)[![Coverage Status](https://camo.githubusercontent.com/4aa8462eea734f73b6cd5f3727b543f5c8d663de462002e1021e249889dff7a0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616c6573616e6368657a722f736c696d2d6170692d777261707065722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/alesanchezr/slim-api-wrapper?branch=master)

Just a small slim wrapper to avoid doing the same things all over again every time I start a new API.

This package is ideal for doing micro-framework architectures where your api is distributed thru several independet servers/developments.

Instalation
-----------

[](#instalation)

```
$ composer require alesanchezr/slim-api-wrapper
```

If you are going to use Authorization headers you have to allow apache to use HTTP Headers in your `.htaccess`:

```
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

```

Creating an API in 1 minute 🧐
-----------------------------

[](#creating-an-api-in-1-minute-)

Here is an example on how to create a simple api with just one `GET /hello` endpoint

```
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
require("./vendor/autoload.php");

$api = new \SlimAPI\SlimAPI([
	'name' => 'My Super Duper API',
	'debug' => true
]);

$api->get('/hello', function (Request $request, Response $response, array $args) use ($api) {
	return $response->withJson(["Hello World"]);
});
```

📝 Adding a readme to the API
----------------------------

[](#-adding-a-readme-to-the-api)

It is good practice to add a README.md file written in markwdown, just call the `$api->addReadme()` method to specify the URI you will want users to access yout `README.md`

```
// here users will GET to path /readme in order to read the readme
$api->addReadme('/readme');

//here users will GET to the root to read the readme file, but you can also specify the name of your readme file.
$api->addReadme('/','./INSTRUCTIONS.md');

```

💻 Adding more endpoints
-----------------------

[](#-adding-more-endpoints)

The API uses [Slim PHP 3.0](http://www.slimframework.com/) on the background, you can add as many endpoints as you like following the [Slim documetation](http://www.slimframework.com/docs/).

💡 Here is a [list of examples you can use](https://github.com/alesanchezr/slim-api-wrapper/tree/master/example).

🔑 JWT Authentication
--------------------

[](#-jwt-authentication)

1. To create private/authenticated the endpoints just add `->add($inst->auth());` at the end of the edpoint like this:

```
    $inst->app->get('/hello/private', function (Request $request, Response $response, array $args){

        return $response->withJson([
            "private" => "object"
        ]);

    })->add($inst->auth()); //here I say I want this endpoint to be private
```

2. Add a secret seed to the API, this will be used as salt for the token generation and you only have to do this step once.

```
// adding an internal seed for random private key generation
// this only has to be done once in the entire API
$api->setJWTKey("adSAD43gtterT%rtwre32@");
```

3. Add at least one client to the API, you can pick a username but the secret key has to be generated using the `generatePrivateKey` method.

```
// pick any username you like for the JWT credentials
$clientId = "alesanchezr";

// generate a key based on that username
$clientKey = $api->generatePrivateKey($clientId);
```

4. Now you can make call any request but you have to add the key to the Request `Authorization` header or as `access_token` on the querystring:

### Using QueriString for authentication

[](#using-queristring-for-authentication)

```
//here is an example in Javascript using QueryString autentication
fetch('https://my_api.com/path/to/endpoint?access_token=ddsfs#@$fsd3425Ds')
    .then(resp => {
        //if the token is wrong you will recive status == 403
        if(resp.status == 403) console.error("You have a wrong access_token token");
        else if(resp.ok) return resp.json()
        else console.error("Uknown problem on the API");
    })
    .then(data => console.log(data))
    .catch(err => console.error("There is a problem on the front-end or the API is down"))
```

### Using `Authorization` header for authentication

[](#using-authorization-header-for-authentication)

```
//here is an example in Javascript using QueryString autentication
fetch('https://my_api.com/path/to/endpoint', {
    'method': 'POST',
    'headers': {
        'Content-Type': ''
        'Authorization': 'JWT asdA@SDad!sdASASDsd453453SDF43'
    },
    'body': JSON.stringify(data)
})
    .then(resp => {
        //if the token is wrong you will recive status == 403
        if(resp.status == 403) console.error("You have a wrong access_token token");
        else if(resp.ok) return resp.json()
        else console.error("Uknown problem on the API");
    })
    .then(data => console.log(data))
    .catch(err => console.error("There is a problem on the front-end or the API is down"))
```

Aditional Info
--------------

[](#aditional-info)

Run the tests:

```
./vendor/bin/phpunit example/with_tests/tests.php --colors
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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 ~13 days

Total

3

Last Release

2564d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61d94492a6ba90c559ef0043808e9a874a2f17d92b11d50337e8fdbba9065d52?d=identicon)[alesanchezr](/maintainers/alesanchezr)

---

Top Contributors

[![alesanchezr](https://avatars.githubusercontent.com/u/426452?v=4)](https://github.com/alesanchezr "alesanchezr (19 commits)")

---

Tags

php-apislim-frameworkslim-phpslim3

### Embed Badge

![Health badge](/badges/alesanchezr-slim-api-wrapper/health.svg)

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

###  Alternatives

[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)

PHPackages © 2026

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