The context object

The Koa context object usually referred to as ctx is a combination of Node's request and response objects into a single object. A new context is created per request. It can be accessed in a middleware function as the first argument in the function.

It is often referenced in middleware as the ctx identifier, as seen in the following example:

app.use(async ctx => {
ctx; // context object
ctx.request; // Request object
ctx.response; // Response object
});

The context object contains methods and properties which either belong specifically to the object or are aliases of methods and properties in the request and response objects.

Both the request and response objects will be discussed in detail in later sections

..................Content has been hidden....................

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