PHP code example of gephart / http

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

    

gephart / http example snippets


$request = (new Gephart\Http\RequestFactory())->createFromGlobals();



use Gephart\Http\Response;
use Gephart\Http\Stream;

class JsonResponseFactory
{
    public function createResponse($content, int $statusCode = 200, $headers = [])
    {
        $body = json_encode($content);

        $stream = new Stream("php://temp", "rw");
        $stream->write($body);

        $response = new Response($stream, $statusCode, $headers);
        return $response;
    }
}

$reponse = (new JsonResponseFactory)->createResponse(["data"=>"data"]);