Free tool
curl to Go
Paste a curl command and get the same request in Go, written with the standard net/http package. No account; the command is only read, never run.
An example: a POST with JSON and a token
curl -X POST 'https://api.example.com/items?page=1' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{"name":"pen","price":2.5}'becomes, in Go:
Go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, err := http.NewRequest("POST", "https://api.example.com/items?page=1", strings.NewReader("{\"name\":\"pen\",\"price\":2.5}"))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode)
fmt.Println(string(data))
}
About the Go code
The code uses only the standard library: http.NewRequest, one req.Header.Set per header, and req.SetBasicAuth for -u.
The body is a strings.NewReader. http.DefaultClient has no time limit: in a real program use an http.Client with a Timeout.
resp.StatusCode is the site's status; the page is read with io.ReadAll(resp.Body), and defer resp.Body.Close() returns the connection.
What the converter understands
The address, -X, -H, -d and its variants, --json, -u, -A, -b, -e, -G and -I, quotes and lines continued with a backslash. Options that do not change the request, such as -L, -s or --compressed, are ignored.
Other languages
curl to Python, curl to JavaScript, curl to PHP, curl to Java, or all eight languages at once.
Need pages for a program, not code? gimmepage fetches any public page in one request: 1 credit a page, failed requests free.