在Intel XDK中为Parse.com REST API或DreamFactory创建Web服务 [英] Create a Web Service in Intel XDK for Parse.com REST API or DreamFactory

查看:112
本文介绍了在Intel XDK中为Parse.com REST API或DreamFactory创建Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人成功地在XDK中为DreamFactory或Parse.com REST API创建了一个新的Web服务吗?我能够通过curl从命令行获得两者的响应,因此似乎应该可行.到目前为止,我还无法使它们中的任何一个起作用.

Has anyone had success creating a new web service in XDK for either DreamFactory or Parse.com REST APIs? I'm able to get a response via curl from a command line for both, so it seems like it should be doable. So far I haven't been able to make either of them work.

作为参考,以下是curl API调用:

For reference, these are the curl api calls:

DreamFactory (首先需要会话打开程序调用):

$ curl -X POST http://ec2-[my server].compute.amazonaws.com:80/rest/user/session -H "X-DreamFactory-Application-Name: testapp" -d '{"email": "test@example.com", "password" : "[my password]"}'


(这将返回一个较大的JSON字符串,其中包含会话ID,如下所述)

$ curl -X GET http://ec2-[my server].compute.amazonaws.com:80/rest/testapp/roles -H "X-    DreamFactory-Application-Name: testapp" -H "X-DreamFactory-Session-Token: [my session]"
{"record":[{"id":1,"rolename":"Agent","description":"agent"},{"id":2,"rolename":"Client","description":"client"},{"id":3,"rolename":"Admin","description":"administrator"}]}


Parse.com :

$ curl -X GET   -H "X-Parse-Application-Id: [my appid]"   -H "X-Parse-REST-API-Key: [my api key]"   https://api.parse.com/1/classes/TestObject
{"results":[{"foo":"bar","createdAt":"2014-07-19T22:07:52.874Z","updatedAt":"2014-07-19T22:07:52.874Z","objectId":"jSpF1RrOy4"}]}


我是JSON新手,所以我怀疑apiconfig.json,testapp.json或testapp.js文件中的一个或多个存在问题.我已经对它们进行了足够的实验,以至于它们现在有点混乱,但是如果有帮助,我可以发布它们.我希望为这些API或类似的API成功创建XDK Web服务的人可以提供一些指导.


I'm new to JSON, so I suspect something is wrong in one or more of my apiconfig.json, testapp.json, or testapp.js files. I've experimented with them enough that they're kind of a mess now, but I can post them if it'll help. I'm hoping someone who has successfully created an XDK web service for either of these APIs or one like them can provide some guidance.

谢谢!

推荐答案

从XDK支持工程师在其HTML5开发人员论坛(

Copied from an XDK support engineer's reply to a separate question on their HTML5 dev forum (http://go.shr.lc/1nr6fsT):

对于需要在URL字符串中包含两个键的API,请将以下字段添加到apiconfig.json文件中:

For APIs that need two keys in the URL string, add these fields to the apiconfig.json file:

"auth": "key",
"keyParam": "apiKey",
"signature": "apiSecret"

可以在.js文件中以凭据.apiKey和凭据.apiSecret的形式访问键值.

The key values can be accessed as credentials.apiKey and credentials.apiSecret in the .js file.

对于需要通过标头使用2个键的API.将所需的标头放在变量key_info中,并在.js文件中,使用以下命令:

For APIs that need 2 keys via the headers. Put the required headers in a variable, key_info, and in the .js file, use this:

return $.ajax({url: url, 
               data: key_info
              });

在您发布的代码中,apiconfig.json文件中列出的服务名称为"parsedbtest",而文件名分别为"parsetestdb.js"和"parsetestdb.json". 通过将apiconfig条目更改为以下内容来解决此问题:

In the code you have posted, the service name listed in apiconfig.json file is 'parsedbtest' while the file names are 'parsetestdb.js' and 'parsetestdb.json'. Fix this by changing the apiconfig entry to:

{
    "parsetestdb": {
        "name": "test db parse.com",
        "dashboardURL": "https://www.parse.com/docs/rest",
        "auth": "key",
        "keyParam": "apiKey",
        "signature": "apiSecret"
    }
}

然后您的parsetestdb.js将是:

Then your parsetestdb.js will be:

(function (credentials) {
  var exports = {};
  exports.TestObject = function (params) {
    var url = 'https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:javascript-key='+ credentials.apiKey +'@api.parse.com/1/classes/TestObject'; //Or credentials.apiSecret.
    return $.ajax({url: url});
  };
  return exports;
})

您还可以使用params.objectId和params.foo输入其他参数.

You can also use params.objectId and params.foo to enter other parameters.

此外,上面使用的方法名称为'TestObject'.这应该与.json文件中的方法名称匹配(因此,不能有空格).因此parsetestdb.json将为:

Also, the method name used above is 'TestObject'. This should match the method name in the .json file (thus, no whitespaces). So the parsetestdb.json will be:

{
   "endpoints":[
      {
         "name":"Methods",
         "methods":[
            {
               "MethodName":"TestObject",
               "HTTPMethod":"GET",
               "URI":"TestObject",
               "RequiresOAuth":"N",
               "parameters":[
                   {
                     "Name":"objectId",
                     "Required":"N",
                     "Location":"query",
                     "Type":"string"
                  },
                  {
                     "Name":"foo",
                     "Required":"N",
                     "Location":"query",
                     "Type":"string"
                  }
               ]
            }
         ]
      }
   ]
}

这篇关于在Intel XDK中为Parse.com REST API或DreamFactory创建Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆