Conversation
Contributor
|
Great ! The only thing that bothers me is that the arguments are not free. The signature of a method must be Maybe we can add flexibly if we give an array of argument to body? Which could be empty and to which we would concatenate |
Member
Author
|
Oh, I forgot to mention, that I added a middleware that should still allow to register any other kinds of custom methods: const { createContext } = require('@feathersjs/feathers');
const { serviceMiddleware } = require('@feathersjs/express');
app.use('/myservice', myservice);
// With custom method handler
app.get('/myservice/:__feathersId/my-method', serviceMiddleware(async ({ req, res, options }) => {
// options.id - __feathersId
// options.params - Service params
// options.data - body
const { params, id } = options;
return app.service('my-service').myCustomMethod(id, params);
}));
// With different params, using the body and returning the context (when using it with hooks)
app.post('/myservice/:myId/myMethod', serviceMiddleware(async ({ req, res, options }) => {
const { myId } = req.params;
const { params, data } = options;
const context = createContext(service, method);
return app.service('my-service').myCustomMethod(myId, data, params, context);
}));It's not as declarative but I'm hoping it to be more flexible and explicit. |
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.
This pull request implements tests and client side functionality for custom service methods outlined in and closes #1976.
On the server a custom service method is added like this:
It can be used via an HTTP and socket API directly as described in #1976.
On the Feathers client it is used like this:
TypeScript has a CustomMethod and client interface: