首页 > Windows开发 > 详细

[Hapi.js] Using the response object

时间:2016-02-28 21:22:58      阅读:201      评论:0      收藏:0      [点我收藏+]

When you use reply method:

let resp = reply(‘hello world‘)

It actually return an response object.

 

By using response object, you can modiy the response‘s status code, header, cookie, type and so on...

server.route({
  method: ‘GET‘,
  path: ‘/‘,
  handler: function(request, reply) {
    let resp = reply(‘hello world‘)
    resp.code(418) // set status code to 418
    resp.type(‘text/plain‘) // set type to text/plain
    resp.header(‘hello‘, ‘world‘) // set header to hello: world
    resp.state(‘hello‘, ‘world‘) // set cookie to hello=world
  }

 

 response object is chainable:

server.route({
   method: ‘GET‘,
   path: ‘/‘,
   handler: function(req, reply){
      reply(‘hello world‘)
        .code(418)
        .type(‘text/plain‘)
        .header(‘hello‘, ‘world‘)
       -state(‘hello‘, ‘world‘)
   }   
})  

 

[Hapi.js] Using the response object

原文:http://www.cnblogs.com/Answer1215/p/5225624.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!