Skip to content

Document how to format response returned to client #634

Closed

Description

@crandmck

Per #624.

I would like to re-format the response returned to client.
I know we could use afterRemote hook, but if doing so, I have to do it every single Models, one by one.
Is there any other solution in that I only need to change the code at place and it will be applied to all Models, something likes that ?

You can use a strong-remoting after hook...

// in my-project/server/boot/hook.js
module.exports = function(server) {
  var remotes = server.remotes();
  // modify all returned values
  remotes.after('**', function (ctx, next) {
    ctx.result = {
      data: ctx.result
    };

    next();
  });
};

Activity

  1. assigned and unassigned on Nov 6, 2014
  2. assigned and unassigned on Nov 20, 2014
  3. crandmck commented on Nov 20, 2014

    @crandmck
    ContributorAuthor

    @ritch please review the above section.

  4. ritch commented on Dec 1, 2014

    @ritch
    Member

    LGTM

  5. assigned and unassigned on Dec 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions