Giter VIP home page Giter VIP logo

fetch's Introduction

fetch

Convert CURL to javascript fetch api: kigiri.github.io/fetch

Alternative options

You can now do this directly from chrome devtools:

feature-screenshot

fetch's People

Contributors

josephrocca avatar kigiri avatar kigiritest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fetch's Issues

Headers spec is incorrect. Should be "headers" not "header

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" } })

Awesome script!

It is a LIFESAVER!!!!

I'd give it five stars *****

Regards

Fix: Body quotes not escaped

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\"}"

Feature Addition Proposal

I'd like to send a PR which creates sendable links:

  • when data is entered, it will change the query string (?curl_input=some_encoded_string)
  • when the page is loaded with a querystring and curl_input parameter in the query string, transform it into that fetch request

let me know if you are interested in accepting such a PR

Curl's --ipv4 does not convert correctly to fetch()

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

bug while creating body

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&currency=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"
})

--data-binary unsupported

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.