import FetchService from './FetchService.js'; /*-- Objects --*/ const fetchService = new FetchService(); async function save(e, btn) { const textarea = document.getElementById('textarea1').value; const headers = buildHeaders(); const jsonFileData = buildJsonFormData(textarea); const response = await fetchService.performPostHttpRequest(window.location.href + 'api/post', headers, jsonFileData); } function buildHeaders(authorization = null) { const headers = { "Content-Type": "application/json", "Authorization": (authorization) ? authorization : "Bearer TOKEN_MISSING" }; return headers; } function buildJsonFormData(text) { return JSON.parse('{"text": "'+ text+'"}'); } const button = document.querySelector(".btn"); button.addEventListener('click', function(e) { save(e, this); });