feat: Allow hooks on all methods and add externalMethods option (#3457)#3638
Closed
marshallswain wants to merge 3 commits intov6from
Closed
feat: Allow hooks on all methods and add externalMethods option (#3457)#3638marshallswain wants to merge 3 commits intov6from
marshallswain wants to merge 3 commits intov6from
Conversation
- Individual method hook chains now work without prior configuration - Add externalMethods option to control HTTP/transport exposure - methods option now controls which methods receive 'all' hooks - Backwards compatible: externalMethods defaults to methods
Deploying feathers-eagle with
|
| Latest commit: |
09bb238
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2c692814.feathers-a8l.pages.dev |
| Branch Preview URL: | https://v6-hooks-all-methods.feathers-a8l.pages.dev |
Deploying feathers-dove with
|
| Latest commit: |
09bb238
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://09e7e607.feathers.pages.dev |
| Branch Preview URL: | https://v6-hooks-all-methods.feathers.pages.dev |
9d59599 to
da29174
Compare
Member
|
I'm wondering if we need to add a new API if we are promoting using decorators going forward. For internal methods you need to list the parameter names of the method anyway to make it useful (to have things like This already works and lets you register hooks on any method: import { hooks } from 'feathers'
class MyService {
@hooks([]).params('message')
internalMethod(message: string) {}
@hooks([])
find() {
}
} |
Member
Author
|
There are still use cases where decorators will not work well, like when using built-in services from a database manager instance. It's a bit verbose to do custom adapter classes just to be able to add hooks. |
Member
Author
|
I forgot about the .params() calls |
Member
|
Wouldn't that work with the object wrapper? import { hooks } from 'feathers'
import { MemoryService } from 'feathers-memory'
const messageService = hooks(new MemoryService(), {
myMethod: middleware([]).params('message')
})
app.use('messages', messageService) |
marshallswain
added a commit
that referenced
this pull request
Jan 28, 2026
- Add @method decorator for configuring custom service methods - Support different argument signatures (not just data, params) - Support different HTTP verbs (GET, POST, PUT, PATCH, DELETE) - Support clean URL paths (e.g., /messages/:id/status) - Support internal-only methods with external: false - Add buildMethodConfig() helper for client configuration - Add InferServiceTypes type helper for typed clients - Update REST client to support custom method paths and verbs - Update services and REST client documentation The @method decorator allows custom methods to be first-class citizens with flexible signatures, proper HTTP verb mapping, and clean URLs instead of relying on X-Service-Method headers. Closes #1976 Replaces #3638
This was referenced Jan 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the feature requested in #3457, allowing hooks to run on all service methods while providing fine-grained control over which methods are exposed externally.
Changes
@feathersjs/feathers
Type Declarations (
declarations.ts)methodsdescription to clarify it controls which methodsallhooks apply toexternalMethodsoption to control HTTP transport exposureService (
service.ts)getExternalMethods()function (defaults tomethodsfor backwards compatibility)normalizeServiceOptions()to includeexternalMethodsHooks (
hooks.ts)allMethodsto hook store to track which methods receiveallhookscollectHooks()to only includeallhooks for methods inallMethodshookMixin()to allow lazy creation of hook managers for any service methodHTTP Transport (
http/index.ts)getExternalMethods()for HTTP access controlTests
allhooks scopingexternalMethodsHTTP behaviorFeatures
1. Individual method hooks work without configuration
methodscontrols which methods receiveallhooks3.
externalMethodscontrols HTTP exposureBackwards Compatibility
externalMethodsis not specified, it defaults tomethodsRelated