cURL ↔ fetch ↔ Python 互轉
貼 cURL 指令,自動轉成 fetch / Python requests / HTTPie。支援多行 \ 續行、單雙引號。
const res = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer abc123",
},
body: "{\"name\":\"Mark\",\"role\":\"qa\"}",
});
const data = await res.json();›如何使用
- 把 cURL 指令貼進左邊(支援
\多行續行、單引號雙引號)。 - 右上切目標格式:fetch(JS)、Python requests、HTTPie。
- 右側即時產出對應程式碼,按
Copy直接貼到你的專案。
Tips
- 支援的 cURL flag:
-X-H-d--data-raw--data-urlencode-u-A-b-G。其他無關 flag(-k-s--compressed等)自動忽略。 - fetch 輸出預設用 await / async,需要包在 async function 裡用。