1. Go to this page and download the library: Download idammi/coolapi 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/ */
idammi / coolapi example snippets
$api->router->get('/test', function ($req, $res) { /** Code here **/ });
$api->router->post('/test', function ($req, $res) { /** Code here **/ });
$api->router->put('/test', function ($req, $res) { /** Code here **/ });
$api->router->delete('/test', function ($req, $res) { /** Code here **/ });
$api->router->post('/user/:id', function ($req, $res) {
// You can now access the id parameter via:
var_dump($req->param('id'));
});
$userRoutes = of routes from other files
$api->router->use('/user', $userRoutes);
// Or with middleware:
$api->router->use('/user', $middleware, $userRoutes);
$req->headers(); // Returns all headers in array form
$res->output([
'foo' => 'bar'
]); // Treats it as a normal status of 200, and outputs as JSON.