feat: Enhanced custom methods with @method decorator by marshallswain · Pull Request #3642 · feathersjs/feathers · GitHub
Skip to content

feat: Enhanced custom methods with @method decorator#3642

Closed
marshallswain wants to merge 3 commits into
v6from
v6-custom-methods
Closed

feat: Enhanced custom methods with @method decorator#3642
marshallswain wants to merge 3 commits into
v6from
v6-custom-methods

Conversation

@marshallswain

@marshallswain marshallswain commented Jan 28, 2026

Copy link
Copy Markdown
Member

This PR adds enhanced custom method support for Feathers v6, allowing custom methods to be first-class citizens with flexible signatures, proper HTTP verb mapping, and clean URLs.

Features

  • @method decorator for configuring custom service methods
  • Different argument signatures (not just data, params)
  • Different HTTP verbs (GET, POST, PUT, PATCH, DELETE)
  • Clean URL paths (e.g., /messages/:id/status instead of X-Service-Method header)
  • Internal-only methods with external: false
  • clientMethods() helper for client configuration

Example

import { feathers, method } from '@feathersjs/feathers'

class MessageService {
  @method({ args: ['id', 'params'], http: 'GET', path: ':id/status' })
  async status(id: Id, params: Params) {
    return { id, status: 'active' }
  }

  @method({ args: ['id', 'params'], http: 'POST', path: ':id/archive' })
  async archive(id: Id, params: Params) {
    return this.patch(id, { archived: true }, params)
  }

  @method({ args: ['data', 'params'], external: false })
  async internalProcess(data: any, params: Params) {
    return { processed: data }
  }
}

app.use('messages', new MessageService())
// GET /messages/123/status -> status('123', params)
// POST /messages/123/archive -> archive('123', params)

Documentation

  • Updated services documentation with full @method decorator guide
  • Updated REST client documentation with custom method paths
  • Added plan document at docs/v6-custom-methods-plan.md

Tests

All 405 tests pass.

Related

- 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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 28, 2026

Copy link
Copy Markdown

- Add clientMethods() to filter and prepare method configs for client
- Remove buildMethodConfig(), getClientMethodConfig(), InferServiceTypes
- clientMethods() filters out external:false methods and strips server-only properties
- Types come from service class definitions, not runtime config
- Remove any types from method.ts, use proper typing
- Add custom methods type test to declarations.test.ts
- Update documentation for new pattern
@marshallswain

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant