Feathers: Quick tip: Disabling a REST method in a service

Created on 26 May 2016  路  8Comments  路  Source: feathersjs/feathers

You might need to restrict access to certain methods in your API. I did not find a cleaner way to configure this when calling "rest()", so I used this quick workaround.

delete exampleService.get;
delete exampleService.find;

Now any calls using the "GET" verb will emit this

{
  "name": "MethodNotAllowed",
  "message": "Method `find` is not supported by this endpoint.",
  "code": 405,
  "className": "method-not-allowed",
  "errors": {}
}

Maybe @daffl or @ekryski have a better way.

Most helpful comment

All 8 comments

@kokujin we have a built-in hook for precisely that 馃槃 http://docs.feathersjs.com/hooks/bundled.html#disable

With even more control over when you want to disable the method.

I had a feeling one of you would say that :). Great! Thanks

@ekryski I disallowed('rest') my patch method, but used it in the remove hook (to make a soft delete, as the commomHook.softDelete() didnt work for me). How can I disable the method and still using it inside as a hook?

The link to the doc is broken. Can you please tell me how I can disable an endpoint completely and only allow it for internal usage on the server?

Thank you I鈥榣l try that later!

@daffl When will feathers-plus/feathers-hooks-common release? Does it production ready?

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings