문법
Request 접근자
Response 접근자
ctx.req, ctx.res
ctx.request, ctx.response
- Koa의 request와 response 객체(Object)를 의미한다.
- Koa.request와 Koa.response의 객체를 출력하면 아래와 같다.
app.use(async ctx => ({ // 미들웨어로 비동기 콜백 함수를 사용
ctx, // context
ctx.request, // Koa Request
ctx.response // Koa Response
});
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()
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=
// Request
{
method: 'GET',
url: '/hello',
header: {
'user-agent': 'vscode-restclient',
'accept-encoding': 'gzip, deflate',
host: 'localhost:3002',
connection: 'close'
}
}
// Response
{
status: 200,
message: 'OK',
header: [Object: null prototype] {
'content-type': 'text/plain; charset=utf-8',
'content-length': '11'
},
body: 'Hello World'
}