Dev Tools

cURL → fetch()

Convert cURL commands to JavaScript fetch() code. Parses -X method, -H headers, -d data, --data-raw, -u auth, and URL. Shows both Promise and async/await versions.

POSThttps://api.example.com/users2 header(s)has body
cURL command
JavaScript fetch() output
async function fetchData() {
  try {
    const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer tok_abc123",
  },
  body: JSON.stringify({"name": "Alice", "email": "alice@example.com"}),
});
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error("Error:", error);
  }
}

fetchData();
Was this page helpful?

Related tools