2015-04-06 19 views
0

嘗試使用回送框架模擬後端服務。我需要使用POST方法來檢索對象。我知道REST服務通常允許POST更新/創建資源,但在這裏,我不能使用GET來檢索數據的資源詳細信息。迴環 - 可以張貼用來檢索資源

在我的情況下,POST數據包含有用於查詢的對象和地發回JSON幾個查詢字段。這是可能的迴環?由於在GET URL中將數據作爲查詢參數發送的安全限制,我無法將GET與查詢參數一起使用。

這裏是POST請求的數據

[ { customer:"sam", city:"noWhere", } ] 

POST事件應該由顧客和城市查詢,然後返回匹配的客戶對象

[ { customer:"sam", postcode:"352345", city:"noWhere", country:"US" } ] 
+0

您可以覆蓋內置的方法。只需閱讀http://docs.strongloop.com/display/public/LB/Customizing+models上的文檔,即「更改內置方法的實現」一節。 –

回答

0

您可以覆蓋默認的環回端點,這樣

// Define custom remote method 
Customer.fetch = function(oRequest, fnResponseCb) { 
    /* Do staff to find customer and finally call fnResponseCb(null, oCustomer) */ 
} 

// Override custom remote method 
Customer.remoteMethod('fetch', { 
    accepts: { 
    arg: 'oRequest', 
    type: 'object', 
    http: { source: 'body' } 
    }, 
    returns: { 
    type: 'object', 
    root: true 
    }, 
    http: { 
    path: '/', 
    verb: 'POST' 
    }, 
    description : 'Fetch Customer' 
});