1. Go to this page and download the library: Download effectra/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/ */
effectra / http-message example snippets
use Effectra\Http\Message\Request;
use Effectra\Http\Message\Uri;
$uri = new Uri('https://api.example.com/users');
$request = new Request('POST', $uri, ['Content-Type' => 'application/json'], '{"name":"John"}');
echo $request->getMethod(); // POST
echo $request->getHeaderLine('Content-Type'); // application/json
$new = $request->withMethod('PUT')->withUri(new Uri('https://other.com'));
// $request is unchanged
$request->setMethod('PATCH')->setUri(new Uri('/local'));
// $request is modified in place
use Effectra\Http\Message\Response;
$response = new Response(200, ['X-Custom' => 'value'], 'OK');
echo $response->getStatusCode(); // 200
echo $response->getReasonPhrase(); // OK
use Effectra\Http\Message\ServerRequest;
$request = ServerRequest::fromGlobals();
echo $request->getMethod(); // GET, POST, etc.
echo $request->getServerParams()['REMOTE_ADDR'];
$input = $request->getParsedBody(); // POST / JSON body
use Effectra\Http\Message\Stream;
// From a string
$stream = new Stream('content');
echo $stream->getContents(); // content
// From a file path (opens automatically)
$stream = new Stream('/path/to/file.txt');
// From a resource
$stream = new Stream(fopen('php://memory', 'r+'));
$stream->write('data');
use Effectra\Http\Message\UploadedFile;
$file = new UploadedFile(
$_FILES['avatar']['tmp_name'],
$_FILES['avatar']['size'],
$_FILES['avatar']['error'],
$_FILES['avatar']['name'],
$_FILES['avatar']['type']
);
$stream = $file->getStream(); // read file contents
echo $file->getClientFilename(); // original name
$file->moveTo('/storage/avatars/1.jpg');