SpacefriendsJS
Version: V
This is how you fetch:
let spf = new Spacefriends(); // Example with GET request spf.fetchData('https://jsonplaceholder.typicode.com/posts/1', 'GET') .then(data => { console.log('Fetched data with GET:', data); }) .catch(error => { console.error('Error with Fetch API:', error); }); // Example with POST request const postData = { title: 'foo', body: 'bar', userId: 1 }; spf.fetchData('https://jsonplaceholder.typicode.com/posts', 'POST', postData) .then(data => { console.log('Fetched data with POST:', data); }) .catch(error => { console.error('Error with Fetch API:', error); });
This is how you use XHR (XMLHttpRequest):
let spf = new Spacefriends(); // Example with GET request spf.fetchDataXHR('https://jsonplaceholder.typicode.com/posts/1', 'GET', null, function(error, data) { if (error) { console.error('Error with XMLHttpRequest:', error); } else { console.log('Fetched data with GET:', data); } }); // Example with POST request const postData = { title: 'foo', body: 'bar', userId: 1 }; spf.fetchDataXHR('https://jsonplaceholder.typicode.com/posts', 'POST', postData, function(error, data) { if (error) { console.error('Error with XMLHttpRequest:', error); } else { console.log('Fetched data with POST:', data); } });