In this episode, we pick up from where we left off by focusing on getting actual responses sent from our registered routes. First, we recap how our router and request are set up, and see that just dispatching a route isn't enough – we need to actually generate and emit an HTTP response that the browser can understand.
We run into an issue by returning a plain string from our route, which throws an error because it's not a valid response object. To solve this, we introduce a proper Response
object (from the same package as our Request
) and go over how to use an "emitter" (specifically, the SAPI emitter from the HTTP handler runner package) to actually send that response back to the client.
We show how to write to the response body instead of just returning a string, so you can display actual content – even though for now it's just the word "home." With this working, you get a taste of how proper HTML can be sent to the browser, and we hint that soon we'll be rendering full templates with Twig rather than hardcoding output.
Finally, we note that our code is still a bit messy since everything's in the bootstrap file, so in the next episode, we'll clean this up and move towards a more organized way of dispatching and registering routes.