Socket
Socket
Sign inDemoInstall

feathers-custom-methods

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    feathers-custom-methods

add custom methods to your feathersjs services


Version published
Maintainers
1
Install size
7.52 kB
Created

Readme

Source

feathers-custom-methods

Add custom methods to your services. For example:

emailService.send(address, subject, content)

Install

npm i feathers-custom-methods

Usage

Server side, configure the plugin:

const customMethods = require('feathers-custom-methods')

app.configure(customMethods({
  methods: {
    email: ['send']  // allow calling app.service('email').send client side
  }
}))

app.service('email').send = function (address, subject, content) {
  // 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:

import customMethods from 'feathers-cucstom-methods/client'

app.configure(customMethods({
  methods: {
    email: ['send']
  }
}))

Now you can use send as a method on the email service client side:

app.service('email').send(address, subject, content)
  .then(response => {
    // handle response
  }).catch(err => {
    // handle error
  })

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.create({
  method: 'send',
  arguments: [arg1, arg2]
})

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

Keywords

FAQs

Last updated on 07 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc