Create a Web Service in Intel XDK for Parse.com REST API or DreamFactory

删除回忆录丶 提交于 2019-12-03 23:06:56

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

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

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

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

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
              });

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"
    }
}

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;
})

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

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"
                  }
               ]
            }
         ]
      }
   ]
}

I do not believe your problem is Intel-XDK related but posting some code may help us solve the issue or give some guidance. Although, if you changed some of the configuration files within the project then you might run into some issues.

AJAX (Asynchronous JavaScript and XML) can be used to interact with REST web services from within your project. There is plenty of examples on Stack Overflow or Google to help you make HTTP requests to the two web services you previous described.

For DreamFactory, see here.

If you have a table named roles in the local MySQL db your URL for a GET should be /rest/db/roles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!