Coder Social home page Coder Social logo

Support request Accept header about hapi HOT 8 CLOSED

hueniverse avatar hueniverse commented on May 19, 2024
Support request Accept header

from hapi.

Comments (8)

matthiasg avatar matthiasg commented on May 19, 2024

this feature is also implemented in restify in a rather unobtrusive manner (http://mcavage.github.io/node-restify/#Routing)

from hapi.

hueniverse avatar hueniverse commented on May 19, 2024

This belongs in a plugin.

from hapi.

chadkouse avatar chadkouse commented on May 19, 2024

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.

hueniverse avatar hueniverse commented on May 19, 2024

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.

chadkouse avatar chadkouse commented on May 19, 2024

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.

hueniverse avatar hueniverse commented on May 19, 2024

If I was going to support conneg, I would do it at the very end in onPreResponse.

from hapi.

felipeleusin avatar felipeleusin commented on May 19, 2024

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.

hueniverse avatar hueniverse commented on May 19, 2024

@felipeleusin you should have it listed on hapijs.com. Just open a PR.

from hapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.