我想在我的hapi路由中进行内容协商,以便我可以返回我的客户可以接受的数据类型。
有了express我会做这样的事情
res.format({
"text/plain": function(){
res.send("Text Response");
},
"text/html": function(){
res.send("HTML Response");
},
"application/json": function(){
res.json({ message: "JSON Response" });
},
"default": function() {
// log the request and respond with 406
res.status(406).send("Not Acceptable");
}
});有没有一种内置的方法可以用hapi做到这一点呢?我看了看API docs,什么也没看到。我是不是被自己的解决方案卡住了?
发布于 2015-02-26 00:28:54
正如@ubaltaci指出的那样,没有内置的方式。
然而,在模块Negotiator之上构建的hapi-negotiator开发中有一个hapi插件。
现在还没有时间尝试,但很快就会做的。(我会更新我的答案)
https://stackoverflow.com/questions/25705050
复制相似问题