问题
I would like to know how to extend CRUD methods created by LoopBack.
I have a model with an attribute public_key
. I would like to build two custom behaviors for the POST
api endpoint for this model.
- generate a public key and set the value
- generate a private key and send it back as a result (using SSL)
How can I extend the default method to implement these behaviors?
回答1:
I was able to override the default method by creating a javascript file under server/boot
.
module.exports = function(app) {
var MyModel = app.models.MyModel;
var create = MyModel.create;
// Overrides POST '/api/MyModel' endpoint
MyModel.create = function(data, done) {
// Do custom things
create.call(MyModel, data, done);
};
};
However I was not able to modify the return value.
回答2:
You can define custom remote methods that are exposed as REST endpoints
来源:https://stackoverflow.com/questions/34623902/extend-the-crud-method-in-loopback