Convert CURL to javascript fetch api: kigiri.github.io/fetch
You can now do this directly from chrome devtools:
Convert CURL to javascript fetch api
Home Page: https://kigiri.github.io/fetch
License: MIT License
Convert CURL to javascript fetch api: kigiri.github.io/fetch
You can now do this directly from chrome devtools:
add method: 'post'
The Fetch API uses the key "headers" not "header" in the options object passed as the second argument to the fetch(..) call. (Source: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Supplying_request_options)
The current GitHub.io site uses "header" incorrectly, which will cause requests to be rejected.
On this Github.io site,
curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer token' 'http://stuff.google.com'
the above input yields:
fetch("http://stuff.google.com", { header: { Accept: "application/json", Authorization: "Bearer token" } })
which should actually be,
fetch("http://stuff.google.com", { headers: { Accept: "application/json", Authorization: "Bearer token" } })
It is a LIFESAVER!!!!
I'd give it five stars *****
Regards
Hi, thanks for the app, it's usefull for converting curl API examples to JS code.
Also here is a problem
With input:
curl -X POST 'URL' -H 'Content-Type: application/json' --data '{"name": "Felix", "color": "black"}'
Output is:
fetch("https://URL", {
body: "{"name": "Felix", "color": "black"}",
headers: {
"Content-Type": "application/json"
},
method: "POST"
})
Take look at body, probably it should be something like: body: "{\"name\": \"Felix\", \"color\": \"black\"}"
I'd like to send a PR which creates sendable links:
let me know if you are interested in accepting such a PR
Someone gave me a curl command:
curl -4 https://icanhazip.com/
and when I put this in the converter, it gives me:
fetch('https://icanhazip.com/')
The fetch command gives me the ipv6 address while curl command gives me the ipv4 addrerss
Try this:
(working example taken from stripe)
curl https://api.stripe.com/v1/charges \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-H "Idempotency-Key: k8OEyGenF6YIitYO" \
-d amount=2000 \
-d currency=usd \
-d description="My First Test Charge (created for API docs)" \
-d source=tok_amex
Actual output(see body):
fetch("https://api.stripe.com/v1/charges", {
body: "amount=2000¤cy=usd&description=My First Test Charge (created for API docs)&source=tok_amex",
headers: {
Authorization: "Basic c2tfdGVzdF80ZUMzOUhxTHlqV0Rhcmp0VDF6ZHA3ZGM6",
"Content-Type": "application/x-www-form-urlencoded",
"Idempotency-Key": "k8OEyGenF6YIitYO"
},
method: "POST"
})
Expected output:
fetch("https://api.stripe.com/v1/charges", {
body: 'amount=2000¤cy=usd&description=My First Test Charge (created for API docs)&source=tok_amex',
headers: {
Authorization: "Basic c2tfdGVzdF80ZUMzOUhxTHlqV0Rhcmp0VDF6ZHA3ZGM6",
"Content-Type": "application/x-www-form-urlencoded",
"Idempotency-Key": "k8OEyGenF6YIitYO"
},
method: "POST"
})
and set the credentials: 'include'
it's simply ignored, maybe can it failsafe to --data?
Also it doesn't specifies the action of the HTTP request, it should say POST at least.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.