PHP code example of sunrise / http-message
1. Go to this page and download the library: Download sunrise/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/ */
sunrise / http-message example snippets
$request = \Sunrise\Http\Message\ServerRequestFactory::fromGlobals();
$request = new \Sunrise\Http\Message\Request\JsonRequest('POST', '/', ['foo' => 'bar']);
$request = new \Sunrise\Http\Message\Request\JsonRequest('POST', '/', [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE, 512);
$request = new \Sunrise\Http\Message\Request\UrlEncodedRequest('POST', '/', ['foo' => 'bar']);
$rfc1738 = \Sunrise\Http\Message\Request\UrlEncodedRequest::ENCODING_TYPE_RFC1738;
$request = new \Sunrise\Http\Message\Request\UrlEncodedRequest('POST', '/', [], $rfc1738);
$rfc3986 = \Sunrise\Http\Message\Request\UrlEncodedRequest::ENCODING_TYPE_RFC3986;
$request = new \Sunrise\Http\Message\Request\UrlEncodedRequest('POST', '/', [], $rfc3986);
$response = new \Sunrise\Http\Message\Response\JsonResponse(200, ['foo' => 'bar']);
$response = new \Sunrise\Http\Message\Response\JsonResponse(200, [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE, 512);
$response = new \Sunrise\Http\Message\Response\HtmlResponse(200, '<h1>Welcome!</h1>');
$stream = new \Sunrise\Http\Message\Stream\FileStream('/folder/file', 'r+b');
$stream = new \Sunrise\Http\Message\Stream\PhpInputStream();
$stream = new \Sunrise\Http\Message\Stream\PhpMemoryStream('r+b');
$stream = new \Sunrise\Http\Message\Stream\PhpTempStream('r+b');
$stream = new \Sunrise\Http\Message\Stream\PhpTempStream('r+b', 1e+6);
$stream = new \Sunrise\Http\Message\Stream\TmpfileStream();
$stream->getMetadata('uri'); // the file path
$stream = new \Sunrise\Http\Message\Stream\TempFileStream();
$stream->getMetadata('uri'); // the file path
try {
} catch (\Sunrise\Http\Message\Exception\ExceptionInterface $e) {
}