feathers-virtual-attribute-hook

0.0.3 • Public • Published

feathers-virtual-attribute-hook

npm package

NPM version Dependency Status

This is experiment. Work in progress!

Feathers hook for add virtual attributes to your service response.

const addVirtualAttribute = require('feathers-virtual-attribute-hook')
 
app.service('/messages').after({
  find: [ 
    addVirtualAttribute({
      webUrl: (message) => `http://example.com/messages/${message.id}`
    })
  ],
  get: [ 
    addVirtualAttribute({
      webUrl: (message) => `http://example.com/messages/${message.id}`
    })
  ]
})

Example

Look example folder for more information.

Test request:

curl -H "Accept: application/json" http://localhost:3030/messages

Server response example:

[
  {
    "id": 1,
    "text": "A message with ID: 1!",
    "webUrl": "http://example.com/messages/1"
  },
  {
    "id": 2,
    "text": "A message with ID: 2!",
    "webUrl": "http://example.com/messages/2"
  },
  {
    "id": 3,
    "text": "A message with ID: 3!",
    "webUrl": "http://example.com/messages/3"
  }
]

Test request:

curl -H "Accept: application/json" http://localhost:3030/messages/1

Server response example:

{
  "id": "1",
  "text": "A new message with ID: 1!",
  "webUrl": "http://example.com/messages/1"
}

Package Sidebar

Install

npm i feathers-virtual-attribute-hook

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • kulakowka