Download the PHP package voku/slim-json-api without Composer
On this page you can find all versions of the php package voku/slim-json-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download voku/slim-json-api
More information about voku/slim-json-api
Files in voku/slim-json-api
Package slim-json-api
Short Description Slim extension to implement fast JSON API's
License MIT
Homepage https://github.com/voku/slim-json-api
Informations about the package slim-json-api
slim-json-api
WARNING: this is only q maintained Fork of "https://github.com/entomb/slim-json-api"
This is an extension to the SLIM framework to implement json API's with great ease.
Installation
Using composer you can add use this as your composer.json
Usage
To include the middleware and view you just have to load them using the default Slim way. Read more about Slim Here (https://github.com/codeguy/Slim#getting-started)
.htaccess sample
Here's an .htaccess sample for simple RESTful API's
example method
all your requests will be returning a JSON output.
the usage will be $app->render((int)$HTTP_CODE, (array)$DATA);
example code
example output
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.
You can optionally throw exceptions, the middleware will catch all exceptions and display error messages.
Embedding response data and metadata in separate containers
It is possible to separate response metadata and business information in separate containers.
To make it possible just init JsonApiView with containers names
Response
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.
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