1. Go to this page and download the library: Download joby/smol-response 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/ */
joby / smol-response example snippets
use Joby\Smol\Response\Response;
// Simple text response
$response = new Response(200, 'Hello World');
// JSON response
$response = Response::json(['status' => 'ok', 'data' => $results]);
// File download
$response = Response::file('/path/to/file.pdf');
// Redirect
$response = Response::redirect('https://example.com', permanent: true);
// Render the response
$renderer = new \Joby\Smol\Response\Renderer();
$renderer->render($response);
$response = (new Response(201, 'Created'))
->cachePublicContent()
->setStatus(200);
// Filename defaults to basename of the file path
$content = new FileContent('/path/to/file.pdf');
$response->content = $content;
// Or override with custom filename
$content = new FileContent('/path/to/file.pdf', 'document.pdf');
$response->content = $content;
$response = new Response(204, new EmptyContent());
// Content automatically supports range requests
$content = new FileContent('/path/to/video.mp4');
// Apply a range manually
$ranged = new AppliedRangeContent($content, 0, 1024);
$response->content = $ranged;
// Renderer automatically sets 206 status and Content-Range header
class TemplateContent extends AbstractContent
{
public function __construct(private string $template, private array $data) {
$this->filename = 'page.html';
}
public function render(): void {
echo $this->engine->render($this->template, $this->data);
}
public function size(): int|null {
return null; // Unknown until rendered
}
}
$renderer = new Renderer();
$renderer->render($response);
// Or test header generation without sending
$headers = $renderer->buildHeaders($response);