Loopback: Getting http request object in model.js

Created on 12 Feb 2015  路  2Comments  路  Source: strongloop/loopback

Is there any way to get http object (containing req, res e.t.c) in model.js file or especially in custom remote method like in rails we get an object named 'itself' in the controller which contains all the http object(req, res, env e.t.c).

on debugging I have seen that only args is being passed to remote method(model.js) from http-context.js file.

Most helpful comment

Try the following as an example:

Model.remoteMethod('custom', {
        isStatic: true,
        http: { verb: 'get', path: '/custom' },
        accepts: [
            { arg: 'req', type: 'object', http: { source: 'req' } },
            { arg: 'res', type: 'object', http: { source: 'res' } }
        ]
});

All 2 comments

Try the following as an example:

Model.remoteMethod('custom', {
        isStatic: true,
        http: { verb: 'get', path: '/custom' },
        accepts: [
            { arg: 'req', type: 'object', http: { source: 'req' } },
            { arg: 'res', type: 'object', http: { source: 'res' } }
        ]
});

@fabien Thanks, it worked... :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Overdrivr picture Overdrivr  路  3Comments

futurus picture futurus  路  3Comments

Overdrivr picture Overdrivr  路  4Comments

daankets picture daankets  路  4Comments

bryannaegele picture bryannaegele  路  4Comments