Explore Library
Code Quiz

Creating a Resource via Fetch

Spot the request-flow bug in a client function that sends data to a REST API.

Codejavascript
async function createUser(user) {
  const res = await fetch('https://api.example.com/users', {
    method: 'GET',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(user)
  });

  if (!res.ok) {
    throw new Error('Request failed: ' + res.status);
  }
  return res.json();
}

This function is meant to create a new user on the server, but it never persists the data. What is the bug?