Search code examples
loopbackjsstrongloop

How to define separate hidden props for GET and POST methods in loopback?


I want some props to be visible for GET method in loopback explorer, but I don't want to show them for POST method, for e.g. id property. How it can be done in loopback?


Solution

  • There are no built-in methods for this.

    You need to do it in after remote for each remote method you want to be different from the default.

    Model.afterRemote('GetMethod', function(ctx, instance, next){
      var instance = ctx.result;
      //reshape it
      ctx.result = instance;
      next();
    });
    

    UPDATE

    If you want to affect this in explorer component so you need to create separate models with null datasource just for showing schema and use that in definition of remote method.

    Model.remoteMethod('GetMethod', {
        accepts: [
          {
            arg: 'req',
            type: 'Object',
            required: true,
            http: {source: 'req'}
          }
        ],
        returns: {root: true, type: 'ModelDTOForSHow'},
        http: {verb: 'get', status: 200, path: '/getter'}
      });
    

    And in ModelDTOForShow you hide some props and in another one some other props