Skip to content

kulakowka/feathers-virtual-attribute-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
}

About

Feathers hook for add virtual attributes to your service response

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published