PHP code example of venndev / vosaka-http

1. Go to this page and download the library: Download venndev/vosaka-http 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/ */

    

venndev / vosaka-http example snippets




declare(strict_types=1);

estInterface;
use vosaka\http\message\Response;
use vosaka\http\middleware\CorsMiddleware;
use vosaka\http\router\Router;
use vosaka\http\server\HttpServer;
use vosaka\foroutines\AsyncMain;

#[AsyncMain]
function main() {
    $router = Router::new()
        ->get('/health', function (ServerRequestInterface $req) {
            return Response::json([
                'status' => 'ok',
                'time' => date('c'),
            ]);
        });

    $server = HttpServer::new($router)
        ->withDebugMode(true)
        ->layer(CorsMiddleware::permissive());

    $server->serve('0.0.0.0:8888');
}



declare(strict_types=1);

nse = Browzr::get('https://httpbin.org/get')->await();
echo $response->getStatusCode() . PHP_EOL;
bash
php tests/server.php