sibartlett / hapi-io

Awesome socket.io plugin for hapi
MIT License
105 stars 18 forks source link

feature request: add ability to specify query/payload without validators #1

Open aaronmccall opened 9 years ago

aaronmccall commented 9 years ago

It would be really useful to be able to provide a data[prop] to query/payload[prop] mapping without having to specify validators for all of them.

What about extending the hapi-io route config to allow the following:

// The original way
config: {
  plugins: {
    'hapi-io': 'get-user'
  }
}

OR

// A new, more configurable way
config: {
  plugins: {
    'hapi-io': {
      event: 'get-user',
      query: ['foo','bar'],
      payload: ['baz', 'qux']
    }
  }
}

If you like the idea, I'd be happy to submit a PR for it.

sibartlett commented 9 years ago

Sound good to me.

I think it would be better to have them nested under "mapping", as below.

plugins: {
  'hapi-io': {
    event: 'get-user',
    mapping: {
      query: ['foo','bar'],
      payload: ['baz', 'qux']
    }
  }
}

I guess this mapping option should override the validation mapping completely? And if the user does not specify this option, then we use the validation mapping.

I'd be happy for you to submit a pull request!

aaronmccall commented 9 years ago

Sounds good! Watch out for incoming code!

sibartlett commented 9 years ago

Looks good so far!

I was just thinking about some other possibilities, and would like your thoughts on them (no need to implement now)...

What do you think of the following two examples? I think the second example, is more inline with how you've implemented the mappings option.

mapping: {
  headers: {
    accept: {
      value: 'application/hal+json'
    }
  },
  query: {
    returnType: {
      src: 'myField'
    }
  }
}
mapping: {
  headers: [
    {
      field: 'accept',
      value: 'application/hal+json'
    }
  ],
  query: [
    {
      field: 'returnType',
      source: 'myField'
    }
  ]
}