返回主页

cURL 转代码

把 curl 命令转成 fetch、axios、Python 或 Go 代码

cURL 命令
POST https://api.example.com/v1/users
代码
const res = await fetch("https://api.example.com/v1/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-demo-token",
  },
  body: JSON.stringify(
    {
      "name": "Alice",
      "email": "alice@example.com",
      "age": 29
    },
  ),
});

if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(data);
18 lines

解析在浏览器内完成,命令不会发出去;支持 -X / -H / -d / -F / -u / -b / -A / -e,以及引号与反斜杠续行。生成的是可直接粘贴运行的代码骨架。