TR

Home / Guides / What Is curl? Basic Flags and Converting a curl Command to fetch

What Is curl? Basic Flags and Converting a curl Command to fetch

Updated: October 13, 2026 · AracMerkezi

▶ Open cURL to Fetch Converter

curl is a widely used tool for sending HTTP requests from the command line. API documentation almost always shows example requests with curl. When you want to run these commands with fetch in browser or Node.js code, knowing how to translate them saves time.

The simplest request

curl https://api.example.com/users

By default it sends a GET request and prints the response body to the screen.

Commonly used flags

FlagMeaning
-X POSTSpecifies the HTTP method
-H "Header: value"Adds a request header
-d 'data'Sends the request body (makes the method POST by default)
-iAlso shows the response headers
-IRequests only the headers (HEAD)
-LFollows redirects
-u username:passwordBasic authentication
-sSilent mode (hides the progress bar)

POST example

curl -X POST https://api.example.com/users \

-H "Content-Type: application/json" \

-H "Authorization: Bearer TOKEN" \

-d '{"name":"Ayşe","age":30}'

The backslash at the end of a line indicates that the command continues (it is different in the Windows command prompt).

The fetch equivalent

The request above is written in JavaScript like this:

fetch("https://api.example.com/users", {

method: "POST",

headers: {

"Content-Type": "application/json",

"Authorization": "Bearer TOKEN"

},

body: JSON.stringify({ name: "Ayşe", age: 30 })

})

.then(r => r.json())

.then(console.log);

The mapping is simple: -X → method, -H → headers, -d → body. If the body is JSON, remember to convert the object to a string with JSON.stringify. The cURL to Fetch Converter translates common flags like this automatically.

What differs in the browser: CORS

A request that works in curl can be blocked in the browser because of CORS. For requests to an API on a different domain, the browser looks for the server's permission headers. curl does not perform this check. If you get a CORS error, the problem is not in your code but in the server's permission settings.

Reading the response

You can tell success from failure by the HTTP status code: 200 is success, 401 unauthorized, 404 not found, 500 server error. You can look up their meanings in the HTTP Status Codes Reference tool and in the HTTP status codes guide. Except for network errors, fetch does not throw an error even on 404 or 500; check the response.ok value.

Security tips

Step by step: running a curl example from API documentation

  1. Identify the URL and the method in the example.
  2. Write the headers (-H) into an object.
  3. Convert the body in -d into a JavaScript object and send it with JSON.stringify.
  4. Check the status code and the body of the response.
  5. Move the token out of the code and into an environment variable.

GET and query parameters

In the request curl "https://api.example.com/search?q=cat&page=2", the URL must be in quotes; otherwise the shell treats the & character as a command separator. On the fetch side, building the URL with new URL and searchParams ensures that special characters are encoded correctly.

Sending form data

A body in the form -d "name=Ayşe&age=30" is sent as application/x-www-form-urlencoded. In fetch, you get the same result if you pass a URLSearchParams object as the body. To send JSON, you need to specify Content-Type: application/json in the header; otherwise the server may not be able to read the body.

Debugging

Limits

The converter covers common flags (method, header, body, basic authentication). Advanced options such as file uploads, cookie files, proxies and client certificates must be adapted by hand.

Frequently asked questions

Which HTTP method does curl -d use?

-d sends a body and makes the method POST by default.

Why does a request that works in curl fail in the browser?

Most often because of CORS; the browser looks for the server's permission headers, while curl does not check for them.

Does fetch throw an error on a 404?

No; it rejects only on a network error. You need to check response.ok.

Tools mentioned in this guide

More guides

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.