In daily development, we often use low-code platform to build our own data sources. We can define the data fields we need. However, with the development of the application, sometimes it is unavoidable to call the interface service provided by the third party. We will take you to use the external data source of the low code platform today.

Creating external data sources

Log in to the low-code console, click “New Data Source” in the data source management menu, and select external data source from the drop-down list:

Enter the data source name and data source id and click ok

Define methods

Click the “Edit” button in the opened page to enter the edit page of the data source

Click “Add Custom Method” on the edit page to add a method

Then we set the method name, logo, intention, methods of type selection of HTTP requests, into the Settings for the city, the url is set to restapi.amap.com/v3/weather/…

Once set up, we can click test, click Run test, and we can see the result of the call

After that, we can click “Exit Parameter Mapping”.

After everything is set up, we click the “OK” button for the Settings to take effect

Transform the results using cloud functions

Through the form of HTTP interface data will be returned as is, but the returned result level is too deep is not conducive to our use, we use the second interface call way to transform the returned interface. We click the new Custom method button in the data source

Method type select cloud function

Enter the following code in the editor:

/** * Use the NPM package request to send HTTP requests. In detail using document can refer to * https://github.com/request/request#readme * / const request = the require (" request "); / / function isSuccessStatusCode(code) {return code >= 200 && code < 300; } module.exports = function (params, context) {// module.exports = function (params, context) { Params return new Promise(function (resolve, reject) {request({url: 'https://restapi.amap.com/v3/weather/weatherInfo?key=5d2d3e6c0d5188bec134fc4fc1b139e0&city=%E5%91%BC%E5%92%8C%E6%B5%A9%E 7%89%B9&extensions=base', method: 'GET', // set json to true, the body of the response result will be automatically converted to an object, // In the POST request, the content-type will be automatically set to application/json json: true }, function (err, response, body) { if (err) return reject(err); if (! isSuccessStatusCode(response.statusCode)) return reject(new Error('request failed: ' + response.statusCode)); return resolve(body.lives); }); }); };Copy the code

Set the input parameter

Click the method test button after the input parameter is defined

Click Run Tests to see the output

As you can see, we filtered some of the unwanted results and kept only the data we needed