res
Set Body
You can either set the body of the response explicitly...
c.res.body = { foo: 'bar' }
...or just return it:
app.get('/', () => {
return { foo: 'bar' }
})
Set Status Code
By default, the status code is 200 - if an error occurs, it will be 500 (unknown error) or 400 (validation error).
Explicitly:
c.res.code = 100Implicitly:
If your response body is a JSON object, you can also add a
codekey to it to set the status code of the response that way.cheetah won't remove the
codefield from your JSON object!app.get('/', () => { return { foo: 'bar', code: 100 } })
Attach Header
c.res.header('foo', 'bar')
Set Cookie
c.res.setCookie('foo', 'bar', options)
Options:
- expires
Date - maxAge
number - domain
string - path
string - secure
boolean - httpOnly
boolean - sameSite
string
Delete Cookie
This method attaches an empty Set-Cookie header to delete the cookie.
c.res.deleteCookie('foo', options)
Options:
- domain
string - path
string
Make a Redirect
The status code is by default set to 307 (temporary redirect).
c.res.redirect(destination, code)
Example:
c.res.redirect('https://google.com', 301)
Calculate Size of Body
A vague estimate of the size of the response body (-1 if it cannot be calculated).
c.res.bodySize