1. Go to this page and download the library: Download matthiasmullie/php-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/ */
matthiasmullie / php-api example snippets
$routes = new MatthiasMullie\Api\Routes\Providers\YamlRouteProvider(__DIR__.'/../config/routes.yml');
$handler = new MatthiasMullie\Api\RequestHandler($routes);
$response = $handler->route(GuzzleHttp\Psr7\ServerRequest::fromGlobals());
$handler->output($response);
namespace MatthiasMullie\ApiExample;
class ExampleController implements MatthiasMullie\Api\Controllers\JsonController
{
public function __invoke(Psr\Http\Message\ServerRequestInterface $request, ResponseInterface $response, array $args)
{
// hey there, I can process your request!
return [
'status_code' => 200,
'hello' => 'world',
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.