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. [RxJS] Completing a Stream with TakeWhile

    Subscribe can take three params: subscribe( (x)=> console.log(x), err=> console.log(err), ()=& ...

  2. 查看哪些进程占用了SWAP分区?

    在日常管理中,我们经常会遇到swap分区使用比较多,那么导致是那些进程使用的呢,其实我们可以通过/proc/pid/下的smaps来获得.使用下面的命令可以列出所有进程占用的swap分区的大小,分别我 ...

  3. 解析Function.prototype.bind

    简介 对于一个给定的函数,创造一个绑定对象的新函数,这个函数和之前的函数功能一样,this值是它的第一个参数,其它参数,作为新的函数的给定参数. bind的作用 bind最直接的作用就是改变this的 ...

  4. OWIN初探(转)

    什么是 OWIN ? OWIN 的全称是 "Open Web Interface for .NET", OWIN 在 .NET Web 服务器和 .NET Web 应用之间定义了一 ...

  5. c#读写cookie

    读 response.SetCokie(new HttpCookie("Color",TextBox1.Text);写 request.Cookies["color&qu ...

  6. C#调用C++的DLL 数据类型转换

    /C++中的DLL函数原型为        //extern "C" __declspec(dllexport) bool 方法名一(const char* 变量名1, unsig ...

  7. poj3579 二分搜索+二分查找

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5468   Accepted: 1762 Descriptio ...

  8. LeetCode-Divdend two Integers

    题目: Divide two integers without using multiplication, division and mod operator. 思路分析 二分法.将除数不断增倍,而结 ...

  9. 【7】用Laravel5.1开发一个简单的博客系统

    声明: 本教程参考Jeffrey way 在laracasts.com上的视频教程,感谢Jeffrey way为大家带来的精彩教程,本教程如有侵权,请及时告知,联系邮箱wanglv93@gmail.c ...

  10. Oracle11g R2学习系列 之五回闪

    Oracle里面有一个回闪的操作,这个貌似sql server是没有的.要使用这个功能,需要用到两个时间内部函数 TIMESTAMP和TO_TIMESTAMP.其中,函数TO_TIMESTAMP的语法 ...