1. Go to this page and download the library: Download philharmony/http-message 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/ */
philharmony / http-message example snippets
use Philharmony\Http\Message\Uri;
use Philharmony\Http\Message\Request;
use Philharmony\Http\Message\Response;
use Philharmony\Http\Message\ServerRequest;
// Create a URI
$uri = Uri::create('https://api.example.com/users');
// Create a client request
$request = Request::create('GET', $uri);
// Server-side request (incoming HTTP request)
$serverRequest = ServerRequest::make(
method: 'POST',
uri: '/users',
body: '{"name":"John"}',
headers: ['Content-Type' => 'application/json']
);
// Access parsed body
$data = $serverRequest->getParsedBody();
// Create a response
$response = Response::create(200)
->withHeader('Content-Type', 'application/json');
echo $response->getStatusCode(); // 200
use Philharmony\Http\Message\Uri;
// From string
$uri = new Uri('https://user:[email protected]:8080/path?query=1#fragment');
// Using factory method
$uri = Uri::create('https://github.com');
// From parts (parse_url compatible)
$uri = Uri::fromParts([
'scheme' => 'https',
'host' => 'api.example.com',
'path' => '/v1/users'
]);