通过聚合物的铁-ajax调用Rest Api

RestApi call through iron-ajax of polymer

我正在开发一个聚合物应用程序,我想调用 RestApi。 这是请求正文的样子

{
    "languageId": Presently English is the only supported language. Always 1, 
    "productCode":"Medicus",
    "timeZoneName":"Time zone name of device. For e.g. Asia/Calcutta",
    "timeZoneOffset": Time zone offset from UTC in milliseconds. For e.g. IST = 19800000,
    "user":{
     "firstName":"First name of the user",
     "lastName":"Last name of the user",
     "middleName":"Middle name of the user",
     "password":"Password provided by the user",
     "userTypeId":2 = Doctor, 3 = User,
     "fields":[
         {
            "Id":1,
            "values":["Mobile number provided by the user”]
         }
     ]
    }
}

我没有正确地了解我应该如何在 iron-ajax 元素的 params='{}' 中指定这些参数。

在你的模板中加入这样的东西(我假设 POST 到你的休息 API,因为你在你的问题中说 body。如果它的 GET 替换 body= params=

<iron-ajax
       id="fetchday"
       url="/api/fetchday"
       handle-as="json"
       content-type="application/json"
       method="POST"
       body="[[params]]"
       last-response="{{results}}"
       on-response="_gotData"
       on-error="_error"></iron-ajax>

并在您的聚合物元素属性中

Polymer({
  is: 'my-element'
  properties: {
    params: {
     type: Object
    } 
  },
  _someFunction: function() {
    this.params = //ASSIGN YOUR JSON OBJECT TO PARAMS HERE
    this.$.fetchday.generateRequest();
  },
  _gotData: function(e) {
    //response data is in both this.results and e.detail.response
 },
 _error: function() {
 }
});