cd .. (all tools)

curl → fetch

Turn a curl command into fetch code.

// Runs in your browser. Nothing you type here is sent anywhere.

A POST request with 2 headers.

As copied from a terminal, documentation or the Network tab of a browser ("Copy as cURL"), for bash or for the Windows command prompt.

The request

method
POST
address
https://api.example.com/v1/orders?expand=lines

Headers

Authorization
Bearer eyJhbGciOiJIUzI1NiJ9.e30.abc
Content-Type
application/json

Body

{"customer":"ada@example.com","lines":[{"sku":"A-1","quantity":2}]}
Read the answer as

fetch

const response = await fetch('https://api.example.com/v1/orders?expand=lines', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer eyJhbGciOiJIUzI1NiJ9.e30.abc',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    customer: 'ada@example.com',
    lines: [
      {
        sku: 'A-1',
        quantity: 2
      }
    ]
  })
});
const data = await response.json();