MockFoxAdvertise

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

  1. Paste the command into the box (multi-line commands with \ continuations are fine) — or copy one from DevTools with Copy as cURL.
  2. Pick the output language. The code updates as you type.
  3. 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.NewRequest and a strings.NewReader body, and sets each header with req.Header.Set.
  • -u becomes req.SetBasicAuth; -F uploads use mime/multipart and w.FormDataContentType().
  • Without -L, a CheckRedirect returning http.ErrUseLastResponse stops Go's default redirect following (up to 10 hops).
  • -k sets InsecureSkipVerify: 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