Skip to content

Instantly share code, notes, and snippets.

@coodoo
Created December 12, 2014 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coodoo/ecc7ffaa414d179eb5e7 to your computer and use it in GitHub Desktop.
Save coodoo/ecc7ffaa414d179eb5e7 to your computer and use it in GitHub Desktop.
loopback remoteMethod demo
// 定義 remote method
loopback.remoteMethod(
Document.findAll,
{
description: 'Find all folder and sub-folders for a user',
accepts: [
// 注意這裏指定從 req.query 裏取值,這是最彈性的方式了
{
http: { source: 'req', required: true, description: 'user Id'}
}
],
returns: {arg: 'result', required: true, type:'Object'},
http: {verb: 'GET', path: '/findAll'}
}
)
// 調用 remote method,注意可從 ctx 身上取得所有傳入的參數
Document.findAll = function(ctx, next) {
// 取得當前用戶 id
var currentUserId = ctx.accessToken.userId.toString();
console.log( 'query str= ', ctx.query );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment