Loopback: How to interact with models without using REST APIs?

Created on 4 Oct 2017  路  8Comments  路  Source: strongloop/loopback

How can I do CRUD operations over a model's data from a diferent model without using Rest api. I mean, if there is a secret infomations which is stored in model to keep secure and out of rest api accessiblity.
How can I access and do crud operations over this model inside of other model without using rest api?

stale

Most helpful comment

Steps:

  • In server/model-config.js, in the model, set public to false (the endpoint's model has been disabled)
  • Inside a hook or a remote hook (or similar), you can call Model.app.models["THE DISABLE MODEL"].specificFunction (for example create, or __get__relatedModels, etc.), and use the same functionalities, but without using directly an endpoint.

I hope to have helped you,

Regards,
Sebasti谩n.

All 8 comments

Do you mean you want to access the "settings" of a model? I think you have to define your custom API endpoint server-sided, and then you can access the settings from client side.

You can access the (eq the properties) settings by permissedModel.settings.properties

maybe have a look into [Model.]app.models.OtherModel.methods ?

@landervs , I mean, for example some secure information about patients are stored in in a table or model (patient model) any manipulation over this model is easily can be done by rest API such as post/get patients if APIs enabled for this model it can be easily accessible form anywhere but if we decide only from server side and inside of models access to content of patients model without using API. something like MVC that controller can work with Model. How we can do this?.

Steps:

  • In server/model-config.js, in the model, set public to false (the endpoint's model has been disabled)
  • Inside a hook or a remote hook (or similar), you can call Model.app.models["THE DISABLE MODEL"].specificFunction (for example create, or __get__relatedModels, etc.), and use the same functionalities, but without using directly an endpoint.

I hope to have helped you,

Regards,
Sebasti谩n.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

You may disable remote methods inside your .js file.

Loopback 2.x:
MyModel.disableRemoteMethod('find', true);

Loopback 3.x:
MyModel.disableRemoteMethodByName('deleteById');

You still be able to access these methods inside your application with AnotherModel.app.models.MyModel.find(); but nobody could do it via REST API.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Overdrivr picture Overdrivr  路  3Comments

bajtos picture bajtos  路  4Comments

germanamz picture germanamz  路  3Comments

ian-lewis-cs picture ian-lewis-cs  路  4Comments

devotox picture devotox  路  4Comments