# 响应(Response)

# 方法

方法名称 参数 返回值
status code 状态码
json data 数据
jsonp callback: 回调
data: 数据
type type 文档类型
attachment filename 文件路径
append field
val
cookie name
value
options
redirect url:地址
code:状态码

# status(code)

router.get("/test/res_status", (ctx, res, next) => {
  res.status(404);
});

# json(data)

router.post("/test/post", (ctx, res, next) => {
  res.json({ result: "post" });
});

# jsonp(callback, data)

router.get("/test/jsonp", (ctx, res, next) => {
  let callback = ctx.query.callback || "nothing";
  res.jsonp(callback, {
    result: "jsonp",
  });
});

# append(field, val)

router.get("/test/set_cookie", (ctx, res, next) => {
  res.append("sessionid", "d9w29skuw32k9duao2l02j3j7d8apkl");
  res.json({ result: "d9w29skuw32k9duao2l02j3j7d8apkl" });
});
router.get("/test/set_cookie", (ctx, res, next) => {
  res.cookie("sessionid", "d9w29skuw32k9duao2l02j3j7d8apkl");
  res.json({ result: "d9w29skuw32k9duao2l02j3j7d8apkl" });
});

# redirect(url, alt)

router.get("/test/redirect", (ctx, res, next) => {
  res.redirect("http://localhost:3000/test/get", 301);
});