cURL से JavaScript Fetch कन्वर्टर
Example
Input:
curl -H "Accept: application/json" https://api.example.com/users
Output:
fetch("https://api.example.com/users",
{
headers: {
"Accept": "application/json"
}
})
.then(function(r){return r.json()})
.then(function(data){console.log(data)})
.catch(function(err){console.error(err)});इस converter के बारे में
हर API guide curl दिखाती है; हर web app को fetch चाहिए। यह converter curl command को ठीक से parse करता है — quoted strings, line-continuation backslashes, -H headers, -X methods, -d/--data bodies (POST का संकेत, जैसे curl करता है), -u basic auth (Authorization header बनता हुआ) और --json — और एक JSON response chain के साथ idiomatic fetch emit करता है। जो flags सिर्फ़ curl binary के लिए मायने रखते हैं (-k, -v, -s, --compressed) वे नकली बनाने के बजाय जानबूझकर हटाए जाते हैं। यह mainstream command shape का translator है; exotic curl features (multi-part form uploads -F के साथ, cookie jars, client certificates) का कोई सीधा fetch equivalent नहीं है और वे dedicated tooling से बेहतर संभलते हैं।
अक्सर पूछे जाने वाले सवाल
मुझे curl command कहाँ से मिलती है?
Chrome/Edge DevTools में: Network tab, किसी request पर right-click → Copy → Copy as cURL। API documentation भी वे प्रदान करता है।
-F form uploads के बारे में क्या?
FormData construction एक अलग code shape है; यह converter header/body JSON-style requests पर focus करता है, जो majority case है।