feathers-custom-methods
Add custom methods to your services. For example:
emailService
Install
npm i feathers-custom-methods
Usage
Server side, configure the plugin:
const customMethods = app app { // implement the method // or implement it through a custom service: // const emailService = { // send(address, subject, content) { /* implementation */ } // } // app.use('/email', emailService)}
Client side, add the client plugin:
app
Now you can use send
as a method on the email
service client side:
app
The code above will call app.service('email').send
with the same arguments server side.
HTTP requests
feathers-custom-methods uses the create method to send data from client to server. In other words, the call service.send(arg1, arg2)
is equivalent to:
service
This means that you can call custom methods through HTTP requests like this:
curl -X POST -d '{ "method": "send", "arguments": ["name@domain.com", "subject", "content"] }' http://localhost:3030/email --header "Content-Type:application/json"
Development
npm test # will start node test.js
This will open a browser window. You must navigate back to terminal yourself. For more, see test.js.
License
MIT