aoculi/slim-api

Starter pack to create an API with slim 3

0.3.0 2017-10-06 23:45 UTC

README

Build Status License

This is a starter Api code for Slim 3.0+. This Api was designed to be a unique starter code when starting a fresh new Api. This project was also built to be easily extensible when we need common endpoint (cf: future endpoint plugins).

Installing

Get last version with Composer.

composer require aoculi/slim-api

Create a new Endpoint

You can add new routes for your api on public/index.php

$app = (new App($config))
    ->addEndpoint(Api\EndPoints\Token\EndPoint::class)
    ->addEndpoint(Api\EndPoints\Home\EndPoint::class)
    ->addEndpoint(Api\EndPoints\MyNewEndPointName\EndPoint::class); 

Authentication

POST /v1/token with good credentials as Basic Auth

curl --request POST \
  --url http://192.168.33.33/v1/token \
  --user admin:test

HTTP/1.1 201 Created Content-Type: application/json { "token": "XXXXXXXXXX", "expires": 1491030210 }

Now you can access all other routes with the token

curl --request GET \
  --url http://192.168.33.33/ \
  --header 'authorization: Bearer {TOKEN}' \

Add a slim-api endpoint extension

You can check the documentation: aoculi/slim-api-users

make endpoint-users

and add the new endpoints in your app

$app = (new App($config))
    ->...
    ->addEndpoint(Api\Authentication\Routes\Authentication::class)
    ->addEndpoint(Api\Users\Routes\Users::class); 

To do

  • aoculi/slim-api-migration (use phinx)
  • aoculi/slim-api-email (use swiftmailer/swiftmailer?)
  • aoculi/slim-api-validation (use respect/validation)
  • aoculi/slim-api-comments (endpoint comments)
  • aoculi/slim-api-likes (endpoint likes)