Fetches data from a specified URL and returns it in the requested format.
The URL or location to fetch data from.
Optional
The format of the returned data ('json' or 'text').
fetchData
Retrieves data from a URL, parsing it as JSON by default or returning it as text if specified.
// Fetching JSON datafetchData('https://api.example.com/data') .then(data => console.log(data)) .catch(err => console.error(err));// Fetching text datafetchData('https://example.com/file.txt', 'text') .then(text => console.log(text)) .catch(err => console.error(err)); Copy
// Fetching JSON datafetchData('https://api.example.com/data') .then(data => console.log(data)) .catch(err => console.error(err));// Fetching text datafetchData('https://example.com/file.txt', 'text') .then(text => console.log(text)) .catch(err => console.error(err));
Fetches data from a specified URL and returns it in the requested format.