1. Go to this page and download the library: Download boxphp/server 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/ */
boxphp / server example snippets
use BoxPHP\Server\Http\Server\HttpServer;
use BoxPHP\Server\Http\Message\HttpResponse;
$server = new HttpServer('http://0.0.0.0:8080');
$server->get('/', function ($request) {
return HttpResponse::json(['hello' => 'world']);
});
$server->get('/users/{id}', function ($request) {
$id = $request['params']['id'];
return HttpResponse::json(['id' => $id]);
});
$server->post('/users', function ($request) {
return HttpResponse::json(['created' => true], 201);
});
$server->start();