use Symfony\Component\HttpFoundation\Response; $response = new Response('Hello, World!', 200, ['Content-Type' => 'text/plain']); $response->send();
use Symfony\Component\HttpFoundation\JsonResponse; $data = ['message' => 'Hello, World!']; $response = new JsonResponse($data, 200, [], true); $response->send();In this example, we create a new JsonResponse object with an array containing the message "Hello, World!" as the response data. We also set the HTTP status code to 200 and enable JSON pretty-printing. Again, we send the response to the client. Both examples use the Symfony component library to create the Response objects.