[Hapi.js] Using the response object
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的更多相关文章
- 【前端】js中new和Object.create()的区别
js中new和Object.create()的区别 var Parent = function (id) { this.id = id this.classname = 'Parent' } Pare ...
- js动态参数作为Object的属性取值
js动态参数作为Object的属性取值var myObj = {"a":1,"b":2};var a = 'a';myObj[a] 就可以获取到 属性a的值了
- JS中==、===和Object.is()的区别
JS中==.===和Object.is()的区别 首先,先粗略了解一下这三个玩意儿: ==:等同,比较运算符,两边值类型不同的时候,先进行类型转换,再比较: ===:恒等,严格比较运算符,不做类型转换 ...
- js中关于new Object时传参的一些细节分析
1, 参数是一个对象,核心js对象(native ECMAScript object)或宿主对象(host object),那么将直接返回该对象. 其生成的对象构造器仍然是所传参数对象的构造器.这样造 ...
- js arrow function return object
js arrow function return object bug filterData: { type: Object, default: () => {}, required: true ...
- [Hapi.js] Replying to Requests
hapi's reply interface is one of it's most powerful features. It's smart enough to detect and serial ...
- [转]Build An Image Manager With NativeScript, Node.js, And The Minio Object Storage Cloud
本文转自:https://www.thepolyglotdeveloper.com/2017/04/build-image-manager-nativescript-node-js-minio-obj ...
- [Hapi.js] Managing State with Cookies
hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...
- [Hapi.js] Request Validation with Joi
hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...
随机推荐
- [RxJS] Getting Input Text with Map
By default, Inputs will push input events into the stream. This lesson shows you how to use map to c ...
- Android ActionBar详解(二):ActionBar实现Tabs标签以及下拉导航
一.添加标签 Tabs 在ActionBar中实现标签页可以实现android.app.ActionBar.TabListener ,重写onTabSelected.onTabUnselected ...
- android 开发随笔 - 开发环境搭建
1.1 问题: 'tools.jar' seems to be not in Android Studio classpath. Please ensure JAVA_HOME points to J ...
- Ubuntu 10.04下安装Opengl glx
1.安装OpenGL Library sudo apt-get install build-essential 2. 安装OpenGL Utilities sudo apt-get install l ...
- Oracle 用户、对象权限、系统权限
--================================ --Oracle 用户.对象权限.系统权限 --================================ 一.用户与模式 ...
- C#基础:集合
C#中的数组实现为 System.Array 类的实例,它们只是集合类(Collection Classes)中的一种类型.集合类一般用于处理对象列表,其功能比简单数组要多,功能大多是通过实现 ...
- cocoa pods 安装 转载
1.打开终端 终端输入 $ruby -v 查看ruby的版本 打印代码: ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64- ...
- oracle数据库ID自增长
使用sequence --创建sequenceCREATE SEQUENCE emp_sequence INCREMENT BY 1 -- 每次加几个 START WITH 1 ...
- NDK编译Python2.7.5
[背景] 网上有一些ndk编译python的做法,但按照教程做总是不成功,可能是环境版本不一样,导致很多地方的配置都不成功. 网上的教程大多只有做法,没有解释,即使按照教程编译成功,很多细节都不知道为 ...
- smarty 常用参数
section的产生是为解决foreach的不足的,与foreach一样,它用于设计模板内的循环块,它较为复杂,可极大程序上满足程序需要,所以在程序中我习惯使用它而不使用foreach,基本原形为:{ ...