Created
December 12, 2014 12:21
-
-
Save coodoo/ecc7ffaa414d179eb5e7 to your computer and use it in GitHub Desktop.
loopback remoteMethod demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 定義 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