Skip to content
API Tools 7 min read

cURL to Code: Convert cURL Commands to JavaScript, Python, Go & More

Learn how to convert cURL commands to fetch API calls, Python requests, Go HTTP, and other languages. Understand cURL flags and translate them to idiomatic code in each language.

ToolsVito Team

cURL: The Universal API Language

cURL is the lingua franca of API documentation — every REST API shows examples as cURL commands. But when you're building an app, you need the request in your language: JavaScript fetch, Python requests, Go's net/http, PHP's curl, or Java's HttpClient. A converter reads the cURL flags and options and generates the equivalent code in your target language with proper syntax, error handling, and conventions.

Anatomy of a cURL Command

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer tok_abc123" \
  -d '{"name":"Jane","email":"jane@example.com"}'

Breaking this down: -X POST sets the HTTP method. -H adds a header. -d sends data in the request body. Other common flags: -u for basic auth, -F for multipart form data, -G to send data as query parameters, and -o to write output to a file.

JavaScript (fetch)

fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer tok_abc123"
  },
  body: JSON.stringify({ name: "Jane", email: "jane@example.com" })
});

Python (requests)

import requests

response = requests.post(
    "https://api.example.com/users",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer tok_abc123"
    },
    json={"name": "Jane", "email": "jane@example.com"}
)

Go (net/http)

import (
    "bytes"
    "net/http"
)

body := []byte('{"name":"Jane","email":"jane@example.com"}')
req, _ := http.NewRequest("POST", "https://api.example.com/users", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer tok_abc123")
client := &http.Client{}
resp, _ := client.Do(req)

Common cURL Flag Translations

  • -X / --request: Sets the HTTP method. Defaults to GET when -d is absent, POST when present.
  • -H / --header: Each header becomes a key-value entry in the target language's header collection.
  • -d / --data: Sends the body as application/x-www-form-urlencoded unless Content-Type is set to application/json. Use --data-raw to send exactly what you type.
  • -u / --user: Basic auth in username:password format. Converts to the Authorization: Basic header.
  • -F / --form: Multipart form data — used for file uploads. Converts to FormData objects.
  • -b / --cookie: Sends a cookie header. Each language has its own cookie mechanism.

Convert cURL to Code Instantly

Paste a cURL command into ToolsVito's cURL Converter — get idiomatic code in JavaScript fetch, Python requests, Go, PHP, Java, and more. All conversion happens in your browser.

Try it now — free, runs in your browser

cURL Converter

cURL → fetch, Python, Go & more