Hapi.js内容谈判

我想在我的hapi路由中进行内容协商,以便返回客户可以接受的数据types。

快递,我会做这样的事情

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文档 ,没有看到任何东西。 我坚持滚动我自己的解决scheme?

正如@ubaltaci所指出的那样,并没有build立起来。

然而在开发hapi-negotiator中有一个hapi插件在模块Negotiator的基础上构build。

还没有时间尝试,但会尽快。 (我会更新我的答案)

Interesting Posts