use Symfony\Component\HttpFoundation\Response; $response = new Response('Hello World!'); $response->send();
use Symfony\Component\HttpFoundation\JsonResponse; $data = [ 'name' => 'John', 'age' => 30, 'email' => 'john@example.com' ]; $response = new JsonResponse($data); $response->send();
use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\BinaryFileResponse; $file = 'path/to/file.pdf'; $response = new BinaryFileResponse($file); $disposition = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'file.pdf' ); $response->headers->set('Content-Disposition', $disposition); $response->send();This will send a file download to the client with the provided file. The `makeDisposition` method is used to set the correct content disposition header for a file download. Package library: Symfony HttpFoundation Component.