StepsEasy
JS Fetch API - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
javascript
// GET request async function getUsers() { const response = await fetch('/api/users'); const data = await response.json(); console.log(data); } // POST request async function createUser(user) { const response = await fetch('/api/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(user) }); return response.json(); } createUser({ name: 'Alice', email: 'alice@example.com' });
Result
Click "Run" to execute the code...
Loading runtime...
Ready
JAVASCRIPT | In-Browser Execution