kulakowka / feathers-virtual-attribute-hook

Feathers hook for add virtual attributes to your service response

Home Page:https://code-typing-tutor.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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"
}
ezoic increase your site revenue

About

Feathers hook for add virtual attributes to your service response

https://code-typing-tutor.com

License:MIT License


Languages

Language:HTML 63.0%Language:JavaScript 37.0%