Skip to content
Sealpaste

Delete all recent work?

This removes the 0 items saved in this browser. Your settings stay.

Stop saving recent work?

New work won't be saved in this browser. The 0 items already saved can stay or go.

cURL to Code

cURL

Paste cURL, or

CtrlV paste · Ctrl↵ run now

Code
Ready
Ln 1, Col 1
Runs in your browser. Nothing you paste is uploaded unless you share it.

Convert a curl command to Python, JavaScript, Node.js, Go, Java, Kotlin, PHP, C#, Swift, PowerShell and more, or HTTPie, Wget or HAR

Paste a curl command and get the same request as a short program for 41 clients in 23 languages, from Python and Node.js to Kotlin, Swift and PowerShell, or as an HTTPie or Wget command or a HAR file, with a note for anything the client can’t repeat.

How to use it

  1. Paste a curl command or open a file with one. A browser’s Copy as cURL works as it is, from bash or Windows cmd.
  2. Pick the language and client. The program sends the request once and prints the status and the body. No command at hand? Pick an Example under Options (GET, form, JSON, basic auth, file upload).
  3. Copy or download the code. Notes above it name any option the client can’t repeat.

Examples

A JSON POST copied from the browser, in Python

Input
curl 'https://api.example.com/v1/orders' -H 'content-type: application/json' --data-raw '{"sku":"A-1","qty":2}'
Result
import requests

headers = {
    'content-type': 'application/json',
}

data = '{"sku":"A-1","qty":2}'

response = requests.post(
    'https://api.example.com/v1/orders',
    headers=headers,
    data=data,
)
print(response.status_code)
print(response.text)

Language: Python (requests). Data makes it a POST, as curl does.

A login and a query, in JavaScript

Input
curl -u ada:hunter2 -G -d q=coffee -d page=2 https://api.example.com/search
Result
const response = await fetch('https://api.example.com/search?q=coffee&page=2', {
  headers: {
    'Authorization': 'Basic ' + btoa('ada:hunter2'),
  },
});
console.log(response.status);
console.log(await response.text());

Language: JavaScript (fetch). -G moves the -d data into the URL, and -u becomes an Authorization header.

A Windows copy (cmd), in PHP

Input
curl ^"https://api.example.com/v1/me^" ^
  -H ^"accept: application/json^" ^
  --compressed
Result
<?php

$ch = curl_init('https://api.example.com/v1/me');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'accept: application/json',
    ],
    CURLOPT_ENCODING => '',
]);
$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n";
echo $response, "\n";

Language: PHP (curl). The ^ escapes and line ends are read as cmd reads them; --compressed becomes CURLOPT_ENCODING.

What a client can’t repeat is named

Input
curl -k -x proxy.local:8080 https://api.example.com/v1/report
Result
fetch can’t skip the certificate check (-k): the request fails if the certificate isn’t valid.
fetch has no proxy setting (-x), so the proxy is left out.

Language: JavaScript (fetch). These notes show above the code. Java can’t repeat -k either; Python, Go, PHP, C#, Ruby and Rust repeat both options.

A JSON POST in PowerShell

Input
curl https://api.example.com/v1/items --json '{"name":"Notebook","price":4.5}'
Result
$headers = @{
    'Accept' = 'application/json'
}

$response = Invoke-RestMethod `
    -Uri 'https://api.example.com/v1/items' `
    -Method 'POST' `
    -Headers $headers `
    -Body '{"name":"Notebook","price":4.5}' `
    -ContentType 'application/json' `
    -MaximumRedirection 0 `
    -SkipHttpErrorCheck `
    -StatusCodeVariable status
$status
$response

Language: PowerShell (Invoke-RestMethod), PowerShell 7. --json sets both headers; redirects stay unfollowed and a 4xx is printed, as curl does without -L and -f.

A file upload in Node.js with axios

Input
curl https://example.com/upload -F 'title=Holiday' -F 'photo=@beach.jpg;type=image/jpeg'
Result
import { openAsBlob } from 'node:fs';
import axios from 'axios';

const form = new FormData();
form.append('title', 'Holiday');
form.append('photo', await openAsBlob('beach.jpg', { type: 'image/jpeg' }), 'beach.jpg');

const response = await axios('https://example.com/upload', {
  method: 'POST',
  data: form,
  maxRedirects: 0,
  responseType: 'text',
  validateStatus: () => true,
});
console.log(response.status);
console.log(response.data);

Language: Node.js (axios). -F builds a multipart form; the file is read from disk when the program runs (Node.js 20 or later).

Where to get a curl command

In Chrome, Edge or Firefox, open the developer tools, go to Network, right-click a request and choose Copy, then Copy as cURL. The command holds the URL, method, headers, cookies and body the page sent. API documentation often gives one too.

On Windows, Chrome and Edge offer Copy as cURL (cmd) and Copy as cURL (bash). Both are read here: cmd’s ^ escapes and line ends, and bash’s quotes, $'…' strings and backslash line breaks.

What is read

Options are read as curl reads them: grouped short options (-sSL), values attached (-XPOST), -d pieces joined with & (--json pieces joined as they are), and -G moving the data into the URL.

  • Method and URL: -X, --url, --url-query, -G, -I, and a POST when there is data.
  • Headers: -H, -A (user agent), -e (referer), -b (cookies), -u (basic login), --oauth2-bearer.
  • Body: -d, --data-raw, --data-binary, --data-urlencode, --json, -F for a multipart form (files included), and -T to send a file.
  • Settings: -k (skip the certificate check), -L (follow redirects), -m (time limit), -x (proxy), --compressed.

The languages and clients

Each program uses a client people use in that language, sends the request once (no retries), follows redirects only with -L, and prints the response status and body, a 4xx or 5xx included, so you can run it as it is and then build on it.

  • JavaScript: fetch (browser or Node.js 18+), XMLHttpRequest and jQuery for a page; Node.js: axios, got, ky, node-fetch, superagent and the built-in http module. Files in the body need Node.js 20 or later.
  • Python: requests (pip install requests) or http.client from the standard library.
  • Java: HttpClient (Java 11+), HttpURLConnection, OkHttp or jsoup; Kotlin with OkHttp; Clojure with clj-http.
  • PHP: the curl extension or Guzzle. Ruby: Net::HTTP or HTTParty. Perl: LWP. Lua: LuaSocket with LuaSec. R: httr2.
  • Go: net/http. Rust: reqwest with its "blocking" feature. C: libcurl. C#: HttpClient (.NET 6+). Swift and Objective-C: URLSession.
  • Dart: package:http. Elixir: Req. OCaml: cohttp-lwt-unix. Julia: HTTP.jl. MATLAB: matlab.net.http.
  • PowerShell 7: Invoke-RestMethod or Invoke-WebRequest. Commands: HTTPie and Wget. Files: a HAR 1.2 log, or the request as plain JSON.

Questions

Does the page send my request?
No. It only writes the code. The request goes out when you run the program yourself.
Why are Content-Length and Accept-Encoding left out?
A copied Content-Length is wrong as soon as the body changes, and a copied Accept-Encoding can make the response arrive compressed to a client that only unpacks what it asked for itself. Each client writes these headers on its own, and a note says when they were left out.
What happens to $VARIABLES in the command?
They are written as they are, not filled in, and a note lists them. Replace them in the code with the values you use.
Can I import the request into Postman, Insomnia or a browser?
Pick HAR file as the language: it writes the request as a HAR 1.2 log, which Postman, Insomnia and the browsers’ developer tools import. JSON writes the same parts as plain JSON for your own scripts.
Why does the code turn off retries and redirects?
curl sends a request once and follows a redirect only with -L. Clients such as got, ky, Req and OkHttp retry or follow redirects on their own, so the code sets them to do what the command did.
Is my command uploaded?
No. Everything runs in your browser, so your command stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. Copied commands often hold tokens and passwords, and the page warns you if it spots one.

Related tools