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}`
})
]
})
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"
}