Конвертер cURL в Fetch

Конвертирует команды curl в JavaScript fetch или axios.

async function main() {
  const response = await fetch('value"}', {
    method: 'POST',
    headers: {
      'Content-Type': ''
    },
    body: "{\"key\":"
  });
  const data = await response.json();
  console.log(data);
}

main();

Часто задаваемые вопросы

Реализация кода

import subprocess
import shlex
import json

# Example cURL command to convert
curl_cmd = """curl -X POST https://api.example.com/data \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer mytoken123' \
  -d '{"name": "test", "value": 42}'"""

# Using Python requests (cURL equivalent)
import requests

url = "https://api.example.com/data"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer mytoken123",
}
data = {"name": "test", "value": 42}

response = requests.post(url, headers=headers, json=data)
print(f"Status: {response.status_code}")
print(f"Body: {response.json()}")

# GET with query params (curl -G)
response = requests.get(
    "https://api.example.com/search",
    headers={"Authorization": "Bearer mytoken123"},
    params={"q": "python", "page": 1},
)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.