Download the PHP package entomb/slim-json-api without Composer
On this page you can find all versions of the php package entomb/slim-json-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download entomb/slim-json-api
More information about entomb/slim-json-api
Files in entomb/slim-json-api
Package slim-json-api
Short Description Slim extension to implement fast JSON API's
License MIT
Homepage https://github.com/entomb/slim-json-api
Informations about the package slim-json-api
slim-jsonAPI
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