Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCustom methods the Feathers way #1976
Comments
|
I think that this is a great addition that will allow more flexibility for building APIs and help keeping the hooks lean and simple. |
|
hello . thanks to public this option. where route findOne in rest api ? |
|
I think that a custom method must also be able to have as arguments There is currently a way to expose custom methods to the desired routes with const { rest } = require('@feathersjs/express')
class MyMessageService {
methods = {
findOne: ['data', 'params'],
resendNotification: ['data', 'params']
}
async create (data, params) {}
@rest.httpMethod('POST', ':__feathersId/find-one')
async findOne (data, params) {}
@rest.httpMethod('POST', ':__feathersId/resend-notification')
async resendNotification (data, params) {}
}
app.use('/messages', new MyMessageService())We could do without |
|
Agreed, supporting an |
|
I also prefer keeping the service options as a separate object. |
|
@daffl I agree, the only thing that bothers me is the constraint of fixed parameters. To determine if there is |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Custom methods are one of the most commonly requested features for Feathers. As the FAQ points out, it is possible to handle 90% of all use cases with the normal CRUD service interface and hooks for workflows. It does however still leave some edge cases that would be good if a service could expose additional methods externally. One reason for this limitation was that it is difficult to secure arbitrary methods properly. The new https://github.com/feathersjs/hooks general purpose hooks make this much easier.
This is why starting at v5, in addition to the existing service methods, it will be possible to register your own custom methods. A custom method has a name and fixed parameters of
(data, params)wheredatais the payload andparamsis the usual service method parameters (including things like provider, authenticated user, query etc.). Method information can be passed asoptionstoapp.use(app.use(path, service, options)). This will also allow to more easily disable existing service methods (or their events) externally.Example
The available options are:
external: If this method should be exposed via transports externally. Otherwise it will just become a normal hook-enabled method internallyevent: The event to send when the method completesCalling via transports
X-Method-Overrideheader.datawill be the body payload.socket.emit(methodName, 'messages', { username: 'dave' }, query)