Páginas

Temas

Herramientas

↑↓moverse↵abriresccerrar
Codificación y seguridad

cURL a código

Pega un comando curl y obtén código en JavaScript fetch, TypeScript, Axios, Python requests, Go, C#, Java o Rust, con los parámetros de consulta, cabeceras y cuerpos JSON o multipart intactos.

Se ejecuta por completo en tu navegador: nada de lo que pegues se sube.

Lenguaje de salida
Presets
1 líneas
POST2 headers0 query params79 bytes de cuerpo
Parsed request0 consulta · 2 cabecera · 0 formulario
Method
POST
Base URL
https://api.example.com/v1/orders
Headers
  • Content-Typeapplication/json
  • Acceptapplication/json
Body
{"customer_id":"cus_1042","items":[{"sku":"SOFT-01","qty":2}],"currency":"USD"}
en vivo
JavaScript · fetch
531 caracteres · 26 líneas
const options = {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
  body: JSON.stringify({
    "customer_id": "cus_1042",
    "items": [
      {
        "sku": "SOFT-01",
        "qty": 2
      }
    ],
    "currency": "USD"
  }),
};

const response = await fetch("https://api.example.com/v1/orders", options);

if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}

const data = await response.json();
console.log(data);

Query params, headers and multipart fields stay intact in every language; HEAD requests print the status and headers instead of parsing a body, and a non-ASCII Basic auth pair is encoded as UTF-8. Flags without an equivalent — output files, proxies, retries — are reported on the left instead of being dropped silently.

Chuleta de opciones curl

referencia rápida
-X POST
Fija el método; curl ya envía POST en cuanto hay un cuerpo -d, así que -X solo hace falta para PUT, PATCH o DELETE.
-H 'Content-Type: application/json'
Repite -H por cada cabecera. Sin Content-Type, el servidor trata el cuerpo JSON como formulario o texto plano.
-d '{"a":1}' / --data-raw
-d quita los saltos de línea y codifica el cuerpo; --data-raw lo envía tal cual, que es lo que quieres para JSON.
-u user:pass
Autenticación básica HTTP. El par se codifica en base64 dentro de Authorization, así que solo es seguro sobre HTTPS.
--json '{"a":1}'
Atajo de curl 7.82+: envía el cuerpo, cambia a POST y añade Content-Type y Accept: application/json si faltan.
-F 'file=@photo.png;type=image/png'
Subida multipart. @ lee un archivo, ;type fija su tipo de contenido y un name=value simple es un campo de texto.
Todas las guías de Node.js