hapi makes handling POST and PUT payloads easy by buffering and parsing them automatically without requiring additional modules or middleware. This post will demonstrate how to handle JSON and form based request payloads via hapi's route configuration.

'use strict'
const Hapi = require('hapi')
const server = new Hapi.Server()
server.connection({ port: 8000 }) server.route({
method: ['POST', 'PUT'],
path: '/',
config: {
payload: {
output: 'data',
parse: true, // parse to json, default is ture
allow: 'application/json' // only accept JSON payloads
}
},
handler: function(request, reply) {
reply(request.payload)
}
}) server.start(() => console.log(`Started at: ${server.info.uri}`))
 

[Hapi.js] POST and PUT request payloads的更多相关文章

  1. [Hapi.js] Request Validation with Joi

    hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...

  2. [Hapi.js] Extending the request with lifecycle events

    Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...

  3. [Hapi.js] View engines

    View engines, or template engines, allow you to maintain a clean separation between your presentatio ...

  4. [Hapi.js] Up and running

    hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...

  5. [Hapi.js] Managing State with Cookies

    hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...

  6. [Hapi.js] Friendly error pages with extension events

    hapi automatically responds with JSON for any error passed to a route's reply()method. But what if y ...

  7. [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 ...

  8. [Hapi.js] Route parameters

    Routing is a fundamental aspect of any framework. In this lesson, you'll learn how to use path param ...

  9. [Hapi.js] Logging with good and good-console

    hapi doesn't ship with logging support baked in. Luckily, hapi's rich plugin ecosystem includes ever ...

随机推荐

  1. C++11 多线程 教学(2)

      C++11开始支持多线程编程,之前多线程编程都需要系统的支持,在不同的系统下创建线程需要不同的API如pthread_create(),Createthread(),beginthread()等, ...

  2. windows系统还原

    windows系统还原 windows 系统还原有两种方法: 方法一.开始-控制面板-系统和安全-备份和还原 (或者开始—所有程序—附件—系统工具—系统还原) 详细请看下面的截图说明 方法二.开机的时 ...

  3. CSS基础知识笔记(三)

    继承 继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代.比如下面代码:如某种颜色应用于p标签,这个颜色设置不仅应用p标签,还应用于p标签中的所有子元素文本,这里子元素为s ...

  4. repeater截取字数

    <%# Eval("ArticleName").ToString().Length > 14 ? Eval("ArticleName").ToStr ...

  5. PowerDesigner Mysql 主键自增、初始值、字符集

    自增 在你所要设为自增型的键上(比如你的id)双击,弹出一个Column Properties对话框,右下角有一个Identify的选择框,选中它OK,就可以了. 再去查看Preview,就能看到AU ...

  6. mysql配置文件my.cnf解析转载

    basedir = path 使用给定目录作为根目录(安装目录). character-sets-dir = path 给出存放着字符集的目录. datadir = path 从给定目录读取数据库文件 ...

  7. BestCoder Round #36 (hdu5200)Strange Class(离线)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Trees Time Limit: 2000/1000 MS (Java/Othe ...

  8. (原)python中使用plt.show()时显示图像

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6039667.html 参考网址: http://matplotlib.org/users/shell. ...

  9. HDU 3966 dfs序+LCA+树状数组

    题目意思很明白: 给你一棵有n个节点的树,对树有下列操作: I c1 c2 k 意思是把从c1节点到c2节点路径上的点权值加上k D c1 c2 k 意思是把从c1节点到c2节点路径上的点权值减去k ...

  10. 慕课linux学习笔记(二)Xshell与虚拟机的连接

    选择使用的是Xshell5 新建连接 连接成功 修改编码方式,字号,颜色 PS: 连接过程中遇到了很多问题,虚拟机的网络连接我最初选择的是桥连,虚拟机和主机相互之间都能ping通但Xshell就是连接 ...