curl to Go converter
Updated Free mock REST & WebSocket APIs
Paste a curl command to get a complete, runnable Go program using only the standard library's net/http package.
POST https://mockfox.dev/api/fake/posts2 headersbody 52 chars
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader(`{
"title": "Hello",
"body": "From curl",
"userId": 1
}`)
req, err := http.NewRequest("POST", "https://mockfox.dev/api/fake/posts", body)
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{
CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(resp.Status)
fmt.Println(string(data))
}🔒 Converted in your browser — your command, tokens and URLs are never sent anywhere.
How to convert a curl command
- Paste the command into the box (multi-line commands with
\continuations are fine) — or copy one from DevTools with Copy as cURL. - Pick the output language. The code updates as you type.
- Copy or download the code, and check any warnings about options that can't be converted.
What the generated Go code does
- Builds the request with
http.NewRequestand astrings.NewReaderbody, and sets each header withreq.Header.Set. -ubecomesreq.SetBasicAuth;-Fuploads usemime/multipartandw.FormDataContentType().- Without
-L, aCheckRedirectreturninghttp.ErrUseLastResponsestops Go's default redirect following (up to 10 hops). -ksetsInsecureSkipVerify: true— only for local testing, never production.
For production code, add a timeout (&http.Client{Timeout: 10 * time.Second}) — Go's default client has none — and check resp.StatusCode.
Need an endpoint to try your code against? Use the free fake REST API or test any HTTP status code.
Related tools
Frequently asked questions
Is my curl command sent to a server?
No. The converter runs entirely in your browser, so API keys, tokens and URLs in your command never leave your device.
Does the generated Go code need any packages?
No. It only imports the standard library (net/http, io, strings, and mime/multipart or crypto/tls when needed).
How do I add a timeout?
Set Timeout on the client, e.g. client := &http.Client{Timeout: 10 * time.Second}, or use http.NewRequestWithContext with a context deadline.
Your business here? Sponsor this tool from $16/week. See placements