码迷,mamicode.com
首页 > Windows程序 > 详细

[Hapi.js] Using the response object

时间:2016-02-28 21:26:02      阅读:328      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!