Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a CURL command to Fetch?

Here is the example.

curl -H 'API-Key: EXAMPLE' https://api.vultr.com/v1/server/label_set --data 'SUBID=576965' --data 'label=example'

I have tried:

fetch("https://api.vultr.com/v1/server/label_set",{
        method:"POST",
        headers:{
            "API-Key":"EXAMPLE"
        },
        data:"SUBID=576965&label=example",

    })

and tried many others, but none of them worked.

Thanks.

like image 499
Zhaoyu ZHONG Avatar asked Jun 22 '16 13:06

Zhaoyu ZHONG


People also ask

How do you fetch curls?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.

What is in a curl command?

What Is the curl Command? curl (short for "Client URL") is a command line tool that enables data transfer over various network protocols. It communicates with a web or application server by specifying a relevant URL and the data that need to be sent or received.


1 Answers

You could try this tool: https://kigiri.github.io/fetch/

Source on github: https://github.com/kigiri/fetch

Output:

fetch("https://api.vultr.com/v1/server/label_set", {
       body: "SUBID=576965&label=example",
       header: {
       "API-Key": "EXAMPLE",
       "Content-Type": "application/x-www-form-urlencoded"
   }
})
like image 114
Herald Smit Avatar answered Sep 28 '22 19:09

Herald Smit