Skip to content

curl to Go Converter

Paste a curl command and get a complete Go program using only the standard library: net/http for the request, mime/multipart for forms and crypto/tls for -k.
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"strings"
)

func main() {
	body := strings.NewReader(`{"title": "Hello", "body": "From curl", "userId": 1}`)

	req, err := http.NewRequest("POST", "https://jsonplaceholder.typicode.com/posts", body)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer YOUR_TOKEN")

	client := http.DefaultClient
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	data, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resp.Status)
	fmt.Println(string(data))
}

Converted in your browser. Commands often contain API keys, so nothing is sent anywhere or saved.

How to convert curl to Go

  1. Paste your curl command (from API docs, a terminal or your browser's dev tools).
  2. The Go code appears instantly, using net/http. Switch tabs to see other languages.
  3. Copy the code and run it; no extra packages are needed.

How curl options map to net/http

curlGo
-X POSThttp.NewRequest("POST", ...)
-H 'Name: value'req.Header.Set(...)
-d '...'strings.NewReader(...)
-F 'name=value'multipart.NewWriter
-u user:passreq.SetBasicAuth(...)
-m 10http.Client{Timeout: 10 * time.Second}
-ktls.Config{InsecureSkipVerify: true}

Tips for the generated Go code

  • http.DefaultClient has no timeout. For anything in production, use a client with Timeout set.
  • Always close resp.Body (the generated code defers it), or connections leak.
  • Check resp.StatusCode before decoding: a 4xx or 5xx response isn't an error to Go's client.

Convert curl to other languages

The same converter writes Python, JavaScript, Node.js (axios), PHP and Ruby. See the cURL converter for every supported option.

Need an API to try it on? Every API in our list of APIs with no key works with a plain curl command.

Frequently asked questions

Does Go's HTTP client follow redirects like curl -L?

Yes, up to 10 by default. To stop at the first response, like curl without -L, set CheckRedirect to return http.ErrUseLastResponse.

How do I send JSON from a Go struct instead of a string?

Marshal it with encoding/json (body, err := json.Marshal(payload)) and pass bytes.NewReader(body) to http.NewRequest, keeping the Content-Type: application/json header.

How do I decode the JSON response in Go?

Define a struct matching the fields you need and use json.NewDecoder(resp.Body).Decode(&result) instead of reading the body into a string.

How do I copy a request as cURL from Chrome?

Open DevTools (F12), go to the Network tab and reload. Right-click the request, choose Copy, then Copy as cURL (bash). Paste it here. Chrome's Windows (cmd) format works too.

Is it safe to paste commands that contain API keys?

Yes. The conversion runs entirely in your browser; nothing you paste is sent to a server, logged or saved. Still, rotate any key you've shared publicly.

More free developer tools