46 lines
1.8 KiB
JavaScript
46 lines
1.8 KiB
JavaScript
Object.defineProperty(exports, "__esModule", { value: 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
|