[Hapi.js] POST and PUT request payloads
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的更多相关文章
- [Hapi.js] Request Validation with Joi
hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...
- [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 ...
- [Hapi.js] View engines
View engines, or template engines, allow you to maintain a clean separation between your presentatio ...
- [Hapi.js] Up and running
hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...
- [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] 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 ...
- [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 ...
- [Hapi.js] Route parameters
Routing is a fundamental aspect of any framework. In this lesson, you'll learn how to use path param ...
- [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 ...
随机推荐
- C# 对象深复制
Mark: //实现IClonable接口并重写Clone方法就可以实现深克隆了 #region ICloneable 成员 public object Clone() { MemoryStream ...
- .net 将xml转换成DateSet
/// <summary> /// 将XML字符串转换成DATASET /// </summary> /// <param name="xmlStr" ...
- 加载gif图过渡效果
加载gif图片,过渡效果: 调用: - (id)initWithGifView:(UIView *)view { self = [super initWithView:view]; if (self) ...
- OpenGL ES 2.0 曲面物体的构建
球体构建的基本原理构建曲面物体最重要的就是找到将曲面恰当拆分成三角形的策略. 最基本的策略是首先按照一定的规则将物体按行和列两个方向进行拆分,这时就可以得到很多的小四边形.然后再将每个小四边形拆分成两 ...
- C/C++中的虚析构函数和私有析构函数的使用
代码: #include <iostream> using namespace std; class A{ public: A(){ cout<<"construct ...
- 洛谷 P1241 括号序列
P1241 括号序列 题目描述 定义如下规则序列(字符串): 1.空序列是规则序列: 2.如果S是规则序列,那么(S)和[S]也是规则序列: 3.如果A和B都是规则序列,那么AB也是规则序列. 例如, ...
- c++模板编程-异质链表
概念: 像一个普通的链表结点中,其中成员next通常是指向同类型结点的指针.这就约束了链表中结点必须是同一类型,从而整个链表都只能保存同一类型的数据.而异质链表则是让next指向任何一种类型,也包括存 ...
- DOM 之selection
有关文章的集合 MOZILLA 开发者网络 selection: MOZILLA DEVELOPER NETWORK document.activeElement MOZILLA DEVELOPER ...
- Mysql存储过程分析
为了搞明白为什么mysql的存储过程是高效的,我们需要理解mysql的执行流程是什么,当输入sql语句之后,mysql会先进行sql语句语法正确性检查,然后再进行编译,然后才执行,最后把结果返回.如下 ...
- HTML5画布(圆形)
案例1: <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8& ...