[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 ...
随机推荐
- java foreach循环为什么不能赋值
直接上代码 public class test4 { public static void main(String args[]){ int [] a=new int[3]; for(int j:a) ...
- (转)Web.config配置文件详解(新手必看)
花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...
- 使用java对sql server进行增删改查
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...
- iOS的Bundle资源束制作
在静态库的制作中,很多时候我们的静态库也是带着文件,图片和多媒体资源的. 若只是直接加入到项目中也是可以,但是,考虑到方便管理(方便插件使用者的管理),我们希望把插件的资源文件打成一个包来管理. 当然 ...
- Sql 函数大全 (更新中...由难到简
1.字符处理类: 1.1 指定指定字符输出的次数 ) 结果:1a1a1a1a1a (5个1a)
- 16 Socket通信(简单例子)
服务端代码: import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Da ...
- C++类中的静态成员变量与静态成员函数的使用
代码: #include <iostream> #include <string> #include <cstdio> using namespace std; c ...
- CODEVS 3139 栈练习3
3139 栈练习3 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 比起第一题,本题加了另外一个操作,访问栈顶元素(编号3,保 ...
- 自动生成代码工具【JAVA版】
发现任何项目无非五类操作:新增.修改.删除.查询详细.查询列表 大多数的服务端基础代码都是相同的,但是每次开发一个新项目都会做很多重复工作,从controller,bean,service,到数据库访 ...
- web app之rem
rem是什么? rem:font size of the root element,是指相对于根元素的字体大小的单位.简单的说它就是一个相对单位. em:font size of the elemen ...