2013-06-19 41 views
2

我需要使用檢索特定數據AngularJS的$ HTTP調用解析RESTful API,因此解析允許我做它處於「--data-進行urlencode發送到哪裏的唯一途徑= { 「STOREID」:2}」來形成捲曲呼叫。

curl -X GET -H "X-Parse-Application-Id:ApplicationId" -H "X-Parse-REST-API-Key: ApiKey" -G --data-urlencode 'where={"storeId":2}' https://api.parse.com/1/classes/Stores/

在這裏看到:https://parse.com/docs/rest#queries-arrays

我能夠返回使用終端JSON結果,但不能含有$ HTTP()。任何人都知道我可以注入 「--data-進行urlencode其中= {」 STOREID 「:2}」 到AngularJS $ HTTP()或$資源()方法?

在這裏看到:http://docs.angularjs.org/api/ng.$http

回答

5

尋找一個解析API的Python的引用,我猜where={"storeId":2}可以附加作爲查詢參數(我無法訪問解析api無法測試此)。從參考:

params = urllib.urlencode({"where":json.dumps({ 
    "arrayKey": 2 
})}) 

在AngularJS您可以在$httpconfig對象param鍵添加查詢參數:

var req = $http({ 
    params: { 
     where: {storeId: 2}, 
    }, 
    headers: { 
     'X-Parse-Application-Id': 'ApplicationID', 
     'X-Parse-REST-API-Key': 'ApiKey' 
    } 
    //... other params, like URL 
}); 

params.where值會自動變成一個JSON字符串。我不知道,如果查詢參數獲得默認編碼的URL,如果沒有,JSON手動編碼它們的應用encodeURIComponent功能。

+0

謝謝你這麼多kmoerman。這解決了我的問題! –

+0

歡迎您。 – kmoerman