Answers.Body: <p>Craft is an MVC application, so most requests initially will get routed to a controller action. Steps 3-6 in our <a href="http://buildwithcraft.com/docs/routing" rel="nofollow">Routing</a> docs page show the various ways that the target controller action is decided.</p>
  
  <p>Controller actions can really do whatever they want with the request at that point, but typically they will perform some level of authorization, and then either perform an action and/or define + send the response.</p>
  
  <p>For example, if you request a template path directly, the request will get routed to the <a href="http://buildwithcraft.com/classreference/controllers/TemplatesController#actionRender-detail" rel="nofollow">templates/render</a> action, which will verify that the template actually exists, and then render and return it, otherwise throw a 404 exception.</p>
  
  <p>Template rendering is ultimately performed by <a href="http://buildwithcraft.com/classreference/services/TemplatesService#render-detail" rel="nofollow">TemplatesService::render()</a>, which is where Twig gets invoked.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-22T10:44:56.350Z
Answers.LastActivityDate: 2015-10-22T10:44:56.350Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Long story short: I've been trying to find out how Craft processes the request and eventually create the output. The search is going deeper and deeper into the core, but it feels like I'm missing out on something.</p>
  
  <p>Is it possible for a plugin to 'fetch' the (full) output of a page generated by Craft?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-22T08:02:30.290Z
Comments.Text: When you say output do you mean the generated HTML from Twig? Do you want to catch the Twig output _before_ it sends it to the browser?
Comments.UserDisplayName: naboovalley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-22T11:45:08.693Z
Comments.Text: yes, but even better would be the output regardless of Twig (i.e. JSON response shouldn't go through Twig)
Comments.UserDisplayName: Chris
Tags: <plugin-development><output>
Title: How is a typical frontend request output generated?
ThreadText: # How is a typical frontend request output generated?
  
  (Asked by: username_0 on 2015-10-22)
  
  Long story short: I've been trying to find out how Craft processes the request and eventually create the output. The search is going deeper and deeper into the core, but it feels like I'm missing out on something.
  
  Is it possible for a plugin to 'fetch' the (full) output of a page generated by Craft?
  
  **Tags:** plugin-development, output
  
  > **Comments:**
  > **username_1**: When you say output do you mean the generated HTML from Twig? Do you want to catch the Twig output _before_ it sends it to the browser?  
  > **username_0**: yes, but even better would be the output regardless of Twig (i.e. JSON response shouldn't go through Twig)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-10-22. Score: 3
  
  Craft is an MVC application, so most requests initially will get routed to a controller action. Steps 3-6 in our [Routing](http://buildwithcraft.com/docs/routing) docs page show the various ways that the target controller action is decided.
  
  Controller actions can really do whatever they want with the request at that point, but typically they will perform some level of authorization, and then either perform an action and/or define + send the response.
  
  For example, if you request a template path directly, the request will get routed to the [templates/render](http://buildwithcraft.com/classreference/controllers/TemplatesController#actionRender-detail) action, which will verify that the template actually exists, and then render and return it, otherwise throw a 404 exception.
  
  Template rendering is ultimately performed by [TemplatesService::render()](http://buildwithcraft.com/classreference/services/TemplatesService#render-detail), which is where Twig gets invoked.
  
  
  ---
  
  