Requests and Responses

Evaluating a Request

A request object is available during page requests and callbacks and is accessed as Jaxer.request.

The Jaxer.Request object contains data about the current request:

  • URL requested
  • headers
  • user agent
  • any posted data
  • query string
  • current application

Getting Data About a Request

Locating the Requested Page on Disk

Sometimes it's necessary to be able to locate the file or directory of the current request on disk. This example returns the location of the file in the requested URL and not, say, the location of the JavaScript file in which the Jaxer.request call is made. For more details on working with files, please refer to the Files chapter.

Preparing the Response

A response object is available during page requests and callbacks and is accessed as Jaxer.response.

The Jaxer.Response object contains data to be returned to the browser as the response to a request. With the response object you can:

  • access and modify request headers
  • completely override the content to return
  • redirect to another url
  • abort the current request

Redirecting to Another URL

Overriding Returned Content

This example shows how to replace the entire content of the response with JSON data. You could also use this technique to return dynamically rendered CSS.