daanvanham / hapi-status

3 stars 0 forks source link

undesirable modifications to response object #1

Closed akrsmv closed 8 years ago

akrsmv commented 8 years ago

Great module, but was wondering, is it possible to have a config setting saying if a response body should include the http status code and also wrapping the actual result in a "result" property or not?

For example:

I use a swaggered-ui plugin where I am saying that on creation of agents (POST to /api/agents) response body will be the created agent:

agentSchema

But using hapi-status, this code

let body = { statusCode: code, result: result };

from the hapi-status repo

is forcing me to change my swagger documentation to say that my response body will not be just the created agent but will be something like

{ statusCode: number, result: agentSchema };

which will further break my logic and pollicy.

daanvanham commented 8 years ago

Hi!

Thanks for this issue and I'm happy that you like the module :)

Your request makes sense! I'll look into it and will get back to you when I have a solution!

daanvanham commented 8 years ago

Sorry for the long wait, but I hope this commit fixes the issue. You can now change/add a delegate and thus perform changes on the response body, as requested.

This example should do the trick for you, if I'm correct:

var status = require('hapi-status');

status.addDelegation('applicationJson', (result) => result);