i'm trying to add a get remote method to my api using loopback 2.0 in order to achieve the same method structure as the default ones, such as :
/myObject/{id}
The way I've tried is :
MyObject.remoteMethod(
'remotemethod', {
http: {
path: '/',
verb: 'get'
},
accepts: [
{arg: 'id', type: 'string'},
],
returns: {
arg: 'status',
type: 'string'
}
}
)
But it only allows me to do this :
http://localhost:3000/api/myObject?id=1
Does anyone knows how i can achieve this ?
Does someone also know how i can add a description to this route to display in the explorer ? The documentation doesn't really say much about this.. I think their documentation is not complete, am i the only one who feels that way ?
Answer for loopback 3.0 (but I assume it works similar for 2.0)
MyObject.remoteMethod(
'remotemethod', {
description: 'This will insert the description',
http: {
path: '/:id',
verb: 'get'
},
accepts: [
{arg: 'id', type: 'number', required: true},
],
returns: {
arg: 'status',
type: 'string'
}
}
)
The trick is to add a required attribute to your id parameter and include the param in the path.
Also see example on how to add description
I do have to agree that the docs are quite incomplete still..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With