DevToolBox

cURL to Code Converter

cURLコマンドをJavaScript, Python, PHP, Goのコードに変換。APIテストの効率化に。

// ここに結果が表示されます

cURL to Code Converterの使い方

cURLコマンドを貼り付けて変換ボタンを押すと、JavaScript (fetch)、Python (requests)、 PHP (curl)、Go (net/http) のコードに変換されます。ヘッダー、リクエストボディ、 HTTPメソッドを自動的に検出して、各言語のイディオムに合ったコードを生成します。 APIドキュメントのcURL例をアプリケーションコードに変換する際に便利です。

How to Use the cURL to Code Converter

This tool converts cURL commands to working code in JavaScript (fetch API), Python (requests), PHP (curl), and Go (net/http). It automatically parses headers, request body, HTTP method, and URL from the cURL command. Perfect for converting API documentation examples into your application code. Supports multi-line cURL commands with backslash line continuations. All processing is done locally.

よくあるエラーと対処 / Common Errors and Fixes

エラー / Error原因 / Cause対処 / Fix
-d と --data-urlencode の混同
-d vs --data-urlencode
-d は生のまま送信。スペースや日本語を含む値はエンコードされない
-d sends raw bytes without encoding
値にスペース・記号がある場合は --data-urlencode を使う
Use --data-urlencode for unescaped values
シェルの引用符でJSONが壊れる
Shell quoting breaks JSON bodies
ダブルクォート内の " や $ がシェルに解釈される
Inner quotes and $ expand inside double quotes
ボディ全体をシングルクォートで囲む(Windowsのcmdでは逆に二重引用符+エスケープ)
Wrap the body in single quotes on POSIX shells
-u の認証情報が変換されない
-u credentials not carried over
-u user:pass は Authorization: Basic ヘッダの糖衣構文
-u is sugar for a Basic auth header
変換後コードでは Authorization ヘッダ(Base64)として明示する
Express it as an explicit Authorization header
GETなのにボディが付く
GET with a body
-d を付けるとcurlは自動でPOSTになるが、-X GET を併用すると矛盾する
-d implies POST; forcing -X GET conflicts
-X の手動指定は基本不要。メソッドは -d / -F の有無に任せる
Drop manual -X; let curl infer the method
マルチパート(-F)が再現できない
Multipart (-F) not reproduced
ファイルアップロードは各言語で FormData / multipart 構築が必要
File uploads need language-specific multipart handling
fetch は FormData、requests は files= 引数で書き換える
Use FormData (JS) or files= (Python)

変換例 / Before & After

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer TOKEN" \
  -d '{"name": "Taro"}'

↓ JavaScript (fetch)

const res = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer TOKEN",
  },
  body: JSON.stringify({ name: "Taro" }),
});

Why browser-only?

A cURL command frequently contains everything an attacker would want: bearer tokens, API keys, cookies, and internal endpoints. Pasting it into a server-backed converter hands all of that to a third party. This converter parses and generates code entirely in your browser — credentials in your command never leave your machine. Verify in the DevTools Network tab: zero requests.

cURLコマンドにはトークンやAPIキーがそのまま含まれます。本ツールは解析・変換の全てが ブラウザ内で完結し、認証情報が外部送信されることはありません。

関連ツール / Related Tools

開発をもっと効率的に

PR