New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to add remote method to a built-in model #763
Comments
@bajtos do we support extending built in models from a model script? Or is this only possible from a boot script. |
Not yet - see #397.
Yes. I'd rather postpone this task until we implement
|
@bajtos when you say
Are you referring to documenting how to add remote method to a built-in model (in a boot script, apparently the only way to do so) or support for extending built-in models in a model script? |
@crandmck I wanted to say that it's better to wait with documentation until we have implemented support for extending built-in models via a model script. The solution based on boot scripts is kind of hacky. Although if extending builtin models is something that many people are asking for, then maybe we should not wait. In which case it would be good to mention that the current solution described in docs is not optimal and that we are planning to implement a better solution in the near future. Here is a corrected boot script: module.exports = function(app) {
var User = app.models.User;
User.greet = function(msg, cb) {
cb(null, 'Greetings... ' + msg);
}
User.remoteMethod(
'greet',
{
accepts: {arg: 'msg', type: 'string'},
returns: {arg: 'greeting', type: 'string'}
}
);
}; |
I agree with @bajtos proposal to wait until |
Same here. |
OK! |
So I was looking for exactly this sort of documentation and the funny thing is I found it here in an issue created to document it but then again not document it :)
I mean it is no hack~ier than the When I put myself in your shoes though ... as a company, maybe you want to field such Qs in google groups and not in the public docs? shrug ... Is that what's going on? |
Does the example really work? Keep getting 401 Authorization Required when invoking that method, despite known good AccessToken. Seems to be coming from loopback/common/models/roles.js . What else do I need to do except above code, to make it work? Did add one line for an HTTP GET for easier testing, so currently I have: module.exports = function(app) {
var User = app.models.User;
User.greet = function(msg, cb) {
cb(null, 'Greetings... ' + msg);
}
User.remoteMethod(
'greet',
{
accepts: {arg: 'msg', type: 'string'},
returns: {arg: 'greeting', type: 'string'},
http: { verb: 'get', path: '/greet' }
}
);
}; Then for URL (with valid token)
I keep getting
Just as a test, same server success with GETting a User with a URL
|
IIRC you need to add User.remoteMethod(
'greet',
{
isStatic: true,
accepts: {arg: 'msg', type: 'string'},
returns: {arg: 'greeting', type: 'string'},
http: { verb: 'get', path: '/greet' }
}
); See also #597. |
Tried variations without and with isStatic: true, and without and with prototype, and both with User.remoteMethod and with loopback.remoteMethod. No luck. |
Please run your app with |
In mailing list Raymond then mentioned required additional step: Add the following ACLs to the
|
Since we were not able to implement /cc @crandmck |
I agree. @bajtos I'd like to assign this (and a few other LB doc issues) to @Sequoia (who is doing some contract work for us) but he is not a collaborator in this repo... Can you do something so I can assign issues to him? PM me if you have questions. |
Writing up docs for this now. Unless I'm mistaken, it looks like methods added in this way do not show up in the API explorer, unfortunately, so I'll note this in the docs. |
Please review: https://docs.strongloop.com/display/APIC/Adding+Remote+Methods+to+Built-In+Models If it looks good, feel free to remove page restrictions and close this ticket. |
Edited and published. Thanks, @Sequoia ! |
Currently, we document how to define a remote method for a custom model, and how to create a custom model that extends a built-in model (to which you could attach a remote method) but NOT how to attach a remote method directly to a built-in model.
Summary (example):
/server/boot/userRemoteMethods.js
.The text was updated successfully, but these errors were encountered: