1. Go to this page and download the library: Download entomb/slim-json-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
entomb / slim-json-api example snippets
$app = new \Slim\Slim();
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
$app->get('/', function() use ($app) {
$app->render(200,array(
'msg' => 'welcome to my API!',
));
});
$app->get('/user/:id', function($id) use ($app) {
//your code here
$app->render(404,array(
'error' => TRUE,
'msg' => 'user not found',
));
});
$app->get('/user/:id', function($id) use ($app) {
//your code here
if(...){
throw new Exception("Something wrong with your request!");
}
});
$app = new \Slim\Slim();
$app->view(new \JsonApiView("data", "meta"));
$app->add(new \JsonApiMiddleware());
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!',
));
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.