[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 ...
随机推荐
- [Angular 2] Using the @Inject decorator
TypeScript is used heavily as we build up our application, but TypeScript isn’t required. If you wan ...
- jquery商城类封装插件
自从解决了定时器的问题后,什么都好弄了 这是仿苏宁商城banner的,当然我没弄得那么好啦,但是我想就是那个缩略图,我没弄好吧,方法我猜想是通过把所有li都放进数组,然后通过遍历,就可以做出相应的效果 ...
- .NET开发人员必须知道的八个网站
对于不熟悉.NET技术的朋友,需要说明一下,.NET提供了一个平台和一些相应的工具,.NET开发人员可以使用它们来在开发Windows桌面,互联网,甚至是手持移动设备上构建极富交互性的应用.很有可能你 ...
- windows消息常量值
WM_NULL = 0WM_CREATE = 1应用程序创建一个窗口WM_DESTROY = 2一个窗口被销毁WM_MOVE = 3移动一个窗口WM_SIZE = 5改变一个窗口的大小WM_ACTIV ...
- hdu5347 MZL's chemistry(打表)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud MZL's chemistry Time Limit: 2000/1000 MS ...
- js兼容性 - 动态删除script标签后 ,定义的函数是否执行
hello.js function hello(){ alert('hello'); } hello.html <!DOCTYPE html> <html lang="en ...
- nyoj-366-D的小L(求全排列)
D的小L 时间限制:4000 ms | 内存限制:65535 KB 难度:2 描述 一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给匡匡 ...
- 行为级和RTL级的区别(转)
转自:http://hi.baidu.com/renmeman/item/5bd83496e3fc816bf14215db RTL级,registertransferlevel,指的是用寄存器这一级别 ...
- NOR flash和NAND flash区别,RAM 和ROM区别d
ROM和RAM指的都是半导体存储器,ROM是Read Only Memory的缩写,RAM是Random Access Memory的缩写.ROM在系统停止供电的时候仍然可以保持数据,而RAM通常都是 ...
- openssl对数组加密解密的完整实现代码
本例是用C实现的对一个数组进行加密,加密到第二个数组,然后解密到另一个数组的完整实现代码. #include <stdio.h> #include <string.h> #in ...