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. Android企业级程序完全退出的解决方案

    一.问题描述 在平常开发的过程中可以发现,很多开发者对于程序的退出都没有去认真的解决.一般要么是一个简单的finish(只是退出当前的activity),要么是其他的方法,比如: 1.第一种方法:首先 ...

  2. correlated subquery and non-correlated subquery

    子查询:嵌套在其他查询中的查询称之. 子查询又称内部,而包含子查询的语句称之外部查询(又称主查询). 所有的子查询可以分为两类,即相关子查询和非相关子查询 1>非相关子查询是独立于外部查询的子查 ...

  3. 代码,显示IPhone剩余磁盘空间

    #include <sys/mount.h> //这段代码示范怎么取得 iPhone 的剩余磁盘空间,还有全部磁盘空间 long long freeSpace() { struct sta ...

  4. My way on Linux - 知识梳理计划

    知识梳理计划图 近期计划把自己学习的工作中用到的Linux知识梳理下,敬请期待.

  5. p标签里面不要放div标签(块元素)

    最好不要在p标签里面嵌套块级元素(如div Ul): <p>我来测试下<div>块元素</div>放在p标签的情况</p> <p>我来测试下 ...

  6. 使用css3属性,大部分浏览器要识别前缀

    例如以下代码的解析 -ms-transform:rotate(7deg); -moz-transform:rotate(7deg); -webkit-transform:rotate(7deg); - ...

  7. ControlStyles(枚举)

    指定控件的样式和行为. 此枚举有一个 FlagsAttribute 特性,通过该特性可使其成员值按位组合.属性: ContainerControl:如果为true,则控件是类似容器的控件. UserP ...

  8. unison实时双向数据同步

    软件下载 ocamlopt下载地址:http://caml.inria.fr Unison下载地址:http://www.seas.upenn.edu/~bcpierce/unison 1.安装uni ...

  9. 用C#代码控制水晶报表中的对象

    在C#代码中调用水晶报表的各个对象:字段对象:FieldObject obj=(FieldObject)oRpt.ReportDefinition.ReportObjects["FieldO ...

  10. unity 之2D游戏简单操作

    unity 做2D项目也很方便.  首先要调整camera的模式,camera 的检视面板参数如下: perspective 模式就是平时用的 模式.摄像机到游戏物体是有角度的张开, 而 orthog ...