Aliases

The context object exposes aliases for common-use properties and methods the request and response objects. These are present to make development faster and reduce the amount of code developers need to write.

For example, the .header property that exists in the request object can be accessed directly from the context object, as seen in the code block as follows:

console.log(ctx.header);

// => { host: 'localhost:1234',
// 'user-agent': 'curl/7.54.0',
// accept: '*/

Similarly, the .body setter that exists in the response object can be accessed directly via the context object, as seen in the following code block:

ctx.body = 'Hello, World';

These are the aliases present for the Request object:

  • ctx.header
  • ctx.headers
  • ctx.method
  • ctx.method=
  • ctx.url
  • ctx.url=
  • ctx.originalUrl
  • ctx.origin
  • ctx.href
  • ctx.path
  • ctx.path=
  • ctx.query
  • ctx.query=
  • ctx.querystring
  • ctx.querystring=
  • ctx.host
  • ctx.hostname
  • ctx.fresh
  • ctx.stale
  • ctx.socket
  • ctx.protocol
  • ctx.secure
  • ctx.ip
  • ctx.ips
  • ctx.subdomains
  • ctx.is()
  • ctx.accepts()
  • ctx.acceptsEncodings()
  • ctx.acceptsCharsets()
  • ctx.acceptsLanguages()
  • ctx.get()

These are the aliases present for the Response object:

  • ctx.body
  • ctx.body=
  • ctx.status
  • ctx.status=
  • ctx.message
  • ctx.message=
  • ctx.length=
  • ctx.length
  • ctx.type=
  • ctx.type
  • ctx.headerSent
  • ctx.redirect()
  • ctx.attachment()
  • ctx.set()
  • ctx.append()
  • ctx.remove()
  • ctx.lastModified=
  • ctx.etag=
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.211.87