Closed avin-kavish closed 4 years ago
The status on ctx
is a shortcut for ctx.response.status
(which also works).
The reason that some some of these properties are available on the Context object, but some aren't is because only the unambiguous appear.
That basically excludes body
, header
, type
and a few others. All of those exist on both the request and the response.
That's not very intuitive...
Would be better if that kind of shortcut cases are not accommodated at all. It can just be written as
app.use(({ req, res }: Context) => {
res.status = 200
res.body = 'Hello world!'
})
which is much cleaner. On that topic, I think req
, res
are as verbose as request
and response
need to be.
Makes sense, but this is unlikely to change at this point. I added the shortcuts to give some familiarity to Koa users, but even then felt it was a bit unneeded. Renaming request/response to req/res to save a few characters is not really a high enough priority.
Why am I setting the response status code on the
ctx
object but the response body atctx.response
? Feels a bit awkward.