fetch Flashcards
1
Q
What does fetch() return?
A
A promise that resolves with a Response object
2
Q
What is the default request method used by fetch()?
A
The GET method
3
Q
How do you specify the request method (GET, POST, etc.) when calling fetch?
A
You can specify the request method as a value in the “method” property of the “init” parameter object, which is the second parameter passed into “fetch()”.
example: fetch('https://example.com/profile', { method: 'GET' }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); });