响应
相关文档:Koa 响应
相关文档:响应(Response)
响应
状态码
typescript
ctx.response.status = 201
状态信息
注意
不可设置中文,否则报错
typescript
ctx.response.message = 'Yes it is OK'1
响应
typescript
response.body = Anything1
Anything:
string响应字符串Buffer响应Buffer格式Stream管道Object||ArrayJSON-字符串化,如果为 对象或数组,则直接转为Jsonnull无内容响应
响应头
设置响应头
typescript
ctx.response.set('a', 'b') // 设置单个
ctx.response.set('c', ['aa', 'bb', 'cc']) // 可设置同 key 多个1
2
2
判断响应头
存在:true
不存在:false
typescript
ctx.response.has('X-RateLimit-Limit');1
< ~/ > MyNote