Curl to Fetch/Axios Converter

Convert curl commands to JavaScript code

0) { code += `,\n headers: {\n`; Object.entries(parsed.headers).forEach(([key, value], index, array) => { code += ` '${key}': '${value}'`; if (index < array.length - 1) code += ','; code += '\n'; }); code += ` }`; } if (parsed.data) { code += `,\n body: '${parsed.data}'`; } code += `\n})`; code += `\n .then(response => response.json())`; code += `\n .then(data => console.log(data))`; code += `\n .catch(error => console.error('Error:', error));`; return code; }, generateAxios(parsed) { let code = `axios({\n`; code += ` method: '${parsed.method.toLowerCase()}',\n`; code += ` url: '${parsed.url}'`; if (Object.keys(parsed.headers).length > 0) { code += `,\n headers: {\n`; Object.entries(parsed.headers).forEach(([key, value], index, array) => { code += ` '${key}': '${value}'`; if (index < array.length - 1) code += ','; code += '\n'; }); code += ` }`; } if (parsed.data) { // Try to parse as JSON for better formatting try { const jsonData = JSON.parse(parsed.data); code += `,\n data: ${JSON.stringify(jsonData, null, 2).split('\\n').join('\\n ')}`; } catch { code += `,\n data: '${parsed.data}'`; } } code += `\n})`; code += `\n .then(response => console.log(response.data))`; code += `\n .catch(error => console.error('Error:', error));`; return code; }, loadExample() { this.curl = \"curl -X POST 'https://api.example.com/users' -H 'Content-Type: application/json' -H 'Authorization: Bearer token123' -d '{\\\"name\\\":\\\"John Doe\\\",\\\"email\\\":\\\"john@example.com\\\"}'\"; this.convert(); }, copyOutput() { navigator.clipboard.writeText(this.output); } }">

Supports -X, -H, -d, --data, --data-raw flags

Error

Features

  • Convert curl commands to modern JavaScript
  • Support for Fetch API and Axios
  • Parse headers, methods, and request data
  • JSON data formatting for better readability
  • ⚠️ Client-side processing - your commands never leave your browser