How to convert curl to Go
- Paste your curl command (from API docs, a terminal or your browser's dev tools).
- The Go code appears instantly, using net/http. Switch tabs to see other languages.
- Copy the code and run it; no extra packages are needed.
How curl options map to net/http
| curl | Go |
|---|---|
-X POST | http.NewRequest("POST", ...) |
-H 'Name: value' | req.Header.Set(...) |
-d '...' | strings.NewReader(...) |
-F 'name=value' | multipart.NewWriter |
-u user:pass | req.SetBasicAuth(...) |
-m 10 | http.Client{Timeout: 10 * time.Second} |
-k | tls.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.