1. Go to this page and download the library: Download ascetic-soft/psr7 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/ */
ascetic-soft / psr7 example snippets
use AsceticSoft\Psr7\HttpFactory;
$factory = new HttpFactory();
// Create a response
$response = $factory->createResponse(200);
$response->getBody()->write('Hello, World!');
// Create a request
$request = $factory->createRequest('GET', 'https://example.com/api/users');
// Create a URI
$uri = $factory->createUri('https://example.com/path?query=1#fragment');
use AsceticSoft\Psr7\Request;
use AsceticSoft\Psr7\Response;
use AsceticSoft\Psr7\ServerRequest;
use AsceticSoft\Psr7\Stream;
use AsceticSoft\Psr7\Uri;
// Request
$request = new Request('POST', 'https://api.example.com/users', [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer token123',
], Stream::create(json_encode(['name' => 'John'])));
// Response
$response = new Response(200, ['Content-Type' => 'text/html']);
// Server Request
$serverRequest = new ServerRequest('GET', '/api/users', serverParams: $_SERVER);
// URI
$uri = new Uri('https://example.com:8080/path?q=1#frag');
echo $uri->getHost(); // "example.com"
echo $uri->getPort(); // 8080
echo $uri->getPath(); // "/path"