cURL to Go Converter
Convert curl commands to Go code using net/http. Paste a command and the Go snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The Go net/http code appears instantly.
- Set up: Nothing to install — net/http is in the standard library.
- Run it: Save as
main.goand rungo run main.go. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no net/http equivalent.
Example
GET with headers → Go net/http
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'package main
import (
"fmt"
"io"
"log"
"net/http"
)
func main() {
req, err := http.NewRequest("GET", "https://api.example.com/v1/users?page=2", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d\n%s\n", resp.StatusCode, respBody)
}Common use cases
- Go services and CLIs
- Kubernetes operators and tooling
- Load and integration tests
Converting curl to Go net/http
Go's standard net/http package needs no dependencies. The code builds an http.Request so method, headers and body are all explicit.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent net/http code. Options that have no net/http equivalent are listed under the editors rather than silently dropped.
Limitations
http.DefaultClienthas no timeout; set one with&http.Client{Timeout: …}in production.- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Why does the code use http.NewRequest instead of http.Post?
http.NewRequest supports any method and lets you set every header from the curl command.
How do I add a timeout?
Create a client such as client := &http.Client{Timeout: 10 * time.Second} and call client.Do(req).
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.