Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Sam_Suresh
Beginner
55 Views

Example of custom Webservice API

Hi there,

I want to use App Designer to create custom webservice data binding and make use of listview to create a searchable database.

I understand there is 3 files need to create. However I couldn't find any tutorial example to create those 3 files precisely. I can use other webservices API such as Rotten Tomatoes. Trying to build something similar using my data for a business app.

I have created a PHP file which read and encode data to JSON format. How I can create a webservice so can be used in App Designer?

Thanks in advance.

 

Tags (2)
0 Kudos
6 Replies
Anjali_G_Intel
Employee
55 Views

Hi Sam,

On this page : https://software.intel.com/en-us/xdk/docs/using-web-services#service_createown, if you go to the "Integrating Your Own Services" section and follow the steps, there are some details on what should go in those 3 files. The "Special Parameters" section would be useful as well. 

This video also explains how to write those files : https://software.intel.com/en-us/videos/integrating-a-new-service

The files loosely follow the https://github.com/mashery/iodocs#api-level-config-details standard.

If you still need some help...When you create a data binding, a file is generated : <your project root>www/xdk/services/service-method.js. This file has the merged code of all .js file of every service. You can also use that as a guide to figure out how to write the .js file for your service. 

These sources would help you kick start writing those files.If you have any finer detail questions, fire away here.

Thanks

Sam_Suresh
Beginner
55 Views

Hi Anjali

Thanks for your reply.

I have viewed these 2 before creating this topic. These refers to other 3rd party services.

In my case, I have a JSON data obtained from a URL. How I can use this data as a data binding in App designer?
I know I can list those data with Javascript. But I'm trying to create as webservice so that I can make use of App Designer features to easily create different views.

This is the data I'm getting from my JSON URL.

data.png

 

Sam_Suresh
Beginner
55 Views

This is a webservice I tried to create which didn't work;
apiconfig.json

{
  "$PHP": {
    "name": "PHP API",
    "description": "A great API",
    "dashboardUrl": "http://developer.mu.my"
  }
}

$PHP.js

(function () {
  var exports = {};
  
  exports.default = function(params) {
    var url = 'http://localhost/databasexdk.php/';
    return $.ajax({url: url, type: 'GET'});
  };
  
  return exports;
})

$PHP.json

{
"endpoints": [
  {
    "name": "title",
    "dashboardUrl": "http://localhost/databasexdk.php/",
    "methods": [
      {
        "MethodName": "methodA1",
        "Synopsis": "Grabs information from the A1 data set"
      },
      { [
          {
            "Name": "path",
            "Required": "Y",
            "Default": "",
            "Type": "string",
            "Description": "Description of the first parameter."
          },
          {
            "Name": "title",
            "Required": "Y",
            "Default": "",
            "Type": "string",
            "Description": "The userId parameter that is in the URI."
          }
        ]
      },
      

    ]
  }
]
}

Thank you

Sam_Suresh
Beginner
55 Views

-

Anjali_G_Intel
Employee
55 Views

Hi Sam,

I am taking a look at this in detail but by glancing at this, I can spot one issue, that is also discussed here : https://software.intel.com/en-us/forums/intel-xdk/topic/633302

It will be fixed in our next release. I will make sure is documented on the web page link I provided. To workaround, update your apiconfig.json to be :

{
  "PHP": {
    "name": "PHP API",
    "description": "A great API",
    "dashboardUrl": "http://developer.mu.my",
    "compatibleProjectTypes":[
          "com.intel.xdk.projecttype.jsapp",
          "com.intel.xdk.projecttype.webapp",    
          "com.intel.xdk.projecttype.iotapp"
      ]
  }
}

I am still looking into this..

Anjali_G_Intel
Employee
55 Views

Another error is in the .json file. If you want the path and title to be parameteres for your method method1, then it should be : 

{
"endpoints": [
  {
    "name": "title",
    "dashboardUrl": "http://localhost/databasexdk.php/",
    "methods": [
      {
        "MethodName": "methodA1",
        "Synopsis": "Grabs information from the A1 data set",
        "parameters": [
          {
            "Name": "path",
            "Required": "Y",
            "Default": "",
            "Type": "string",
            "Description": "Description of the first parameter."
          },
          {
            "Name": "title",
            "Required": "Y",
            "Default": "",
            "Type": "string",
            "Description": "The userId parameter that is in the URI."
          }
        ]
      }
      

    ]
  }
]
}

If you don't want the parameters , then it will be : 

{
"endpoints": [
  {
    "name": "title",
    "dashboardUrl": "http://localhost/databasexdk.php/"
  }
]  
}

 

Reply