curl to Go (net/http)

Paste a curl command and get Go code that uses only the standard library net/http, including the method, headers, body, basic auth, multipart form fields and the insecure and redirect flags.

Use the tool

Why this tool exists

Go developers often get an API example as a curl command. Translating it means building a request, setting each header, handling the body reader and remembering to close the response body. Multipart uploads are the most tedious part because they need a writer and a content type with a boundary.

This converter produces that code with the standard library only, so there are no new dependencies to add. It supports the common flags, while proxies, certificates and retries are ignored and need your own configuration. Curl commands usually contain secrets such as API keys or passwords, so it helps that nothing is uploaded. Move any real credential out of the code and into configuration before you commit it.

How to use it

  1. Paste your curl command into the input box.
  2. Read the generated Go program in the output.
  3. Copy it into a main.go file or into your own function.
  4. Run it with go run, and replace secrets with environment variables.

Frequently asked questions

Does it need any external packages?

No. The generated code uses only net/http and other standard library packages, so it builds with a plain Go installation and no go get step.

What happens to curl options that are not supported?

Proxies, client certificates and retries are ignored, so the generated request will not use them. Add a custom Transport or retry loop by hand if your real request depends on them.

How is a multipart form handled?

Fields given with -F are written with the standard mime/multipart writer, and the Content-Type header with the boundary is set from it. File parts need a real file path on your machine when you run the code.