Comments (8)
this feature is also implemented in restify in a rather unobtrusive manner (http://mcavage.github.io/node-restify/#Routing)
from hapi.
This belongs in a plugin.
from hapi.
Does a plugin exist yet? If not I may be interested in creating one. Currently I'm using the negotiator package and hacking it together like:
var availableMediaTypes = ['text/html', 'application/json']
var negotiator = new Negotiator(request.raw.req);
var mime = negotiator.preferredMediaType(availableMediaTypes);
switch (availableMediaTypes.indexOf(mime)) {
case 1:
//json version
...
break;
case 0:
default:
//html version
...
break;
}
if the route config could include a section to indicate the supported media types, and maybe even indicate the handler per media type, then a plugin should be able to be built to call the handler automatically based on the requested media type.
from hapi.
How do you use it in your app? Do you generate one internal representation in the handler and then transform it at the end? or do you have different handlers?
from hapi.
I could see how both could be useful, however in my app so far I'm using a single handler / single(ish) internal representation / transform --chad
On Tue, Dec 31, 2013 at 2:07 AM, Eran Hammer [email protected]
wrote:
How do you use it in your app? Do you generate one internal representation in the handler and then transform it at the end? or do you have different handlers?
Reply to this email directly or view it on GitHub:
#252 (comment)
from hapi.
If I was going to support conneg, I would do it at the very end in onPreResponse.
from hapi.
I saw this and ended up making a plugin that fitted my needs https://github.com/felipeleusin/hapi-negotiator it's my first hapi plugin but I hope it helps someone used in my project but not sure about the api/configuration options
from hapi.
@felipeleusin you should have it listed on hapijs.com. Just open a PR.
from hapi.
Related Issues (20)
- Buffer response with binary status validation always throws 500 HOT 1
- Node sockets timeout after 2 minutes by default HOT 1
- Application errors are not logging, only generating Boom "Internal Server Error" logs HOT 2
- Open-source latest v16 HOT 1
- Cannot bind to Fully qualified domain name (FQDN) HOT 2
- Why does the credentials CORS options accept only false? HOT 4
- [TS] Defining the handler and the return type
- Need help in migrating Hapi application to v20.0.1 HOT 1
- Cookie Partition support
- No response when payload is large HOT 2
- Support lambda direct requests over HTTPS HOT 1
- Catbox catbox-memory throws an error but it is not handled properly HOT 1
- Request object does not have query object populated HOT 1
- Handling Expect: 100-continue HOT 4
- Build issues HOT 3
- HTTP_METHODS_PARTIAL_LOWERCASE is missing `head` HOT 1
- hapi jwt package not able to recognize comma separated cookie as JWT HOT 3
- Nextjs is not supported as a server HOT 2
- multipart validation doesn't comply with new fetch api
- Missing maxParts type in route.d.ts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi.