luboskrnac luboskrnac - 1 year ago 87
Javascript Question

How to disable certain HTTP methods (e.g. POST) for PersistedModel in LoopBack framework

When you create model in LoopBack framework, you can inherit from PersistedModel class. This way all the HTTP methods are generated. I am wondering how can I disable certain HTTP methods?

One option is to override functions from PersistedModel with empty logic, but want method to disappear from Swagger API explorer.

Answer Source

Found answer in documentation. For example this disables PersistedModel.deleteById:

var isStatic = true;
MyModel.disableRemoteMethod('deleteById', isStatic);

So it looks like you it's not possible to disable all DELETE actions at the same time. For example method PersistedModel.deleteAll remains accessible in given example.

Developer must disable each relevant method from PersistedModel class explicitly.

Relevant docs are here:


  • Hiding methods and REST endpoints
  • Hiding endpoints for related models
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download