Files
Undecked/Backend/dist/Integrations/buildin/http/http.js
2023-08-29 19:55:48 +02:00

45 lines
1.7 KiB
JavaScript

exports.__esModule = true;
var axios = require('axios')["default"];
module.exports = function (api) {
//Register a action
api.registerAction('request', function (actionAPI) {
//Handle the action when executed
actionAPI.handle(function (properties, status) {
axios[properties.method](properties.address)
.then(function (response) {
status('Request has been delivered.');
})["catch"](function (error) {
status('Unable to deliver request.', 'error');
});
});
//Handle the interactive editor
actionAPI.onOpenEditor(function (editorAPI, properties) {
var method = properties.method != undefined ? properties.method : 'get';
var address = properties.address != undefined ? properties.address : '';
editorAPI.onFieldChanges(function (fields) {
var fieldValues = editorAPI.tools.objectifyFieldsValues(fields);
editorAPI.saveProperties({ method: fieldValues.method, address: fieldValues.address });
});
editorAPI.setFields([
{
id: 'method',
name: 'Method',
type: 'select',
value: method,
values: [
{ id: 'get', text: 'GET' },
{ id: 'post', text: 'POST' },
{ id: 'put', text: 'PUT' }
]
},
{
id: 'address',
name: 'Address',
type: 'text',
value: address
}
]);
});
});
};
//# sourceMappingURL=http.js.map