# Convert a cURL POST request to Swift

Paste any curl POST command and get clean Swift code using URLSession. Runs entirely in your browser — headers, auth, and JSON bodies map to idiomatic Swift.

## Example

```bash
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada","email":"ada@example.com"}'
```

## What the converter handles

- Request-line method (POST) and target URL are extracted from the curl command exactly as written — no case-folding, no path rewriting.
- Every -H header maps to a Swift header entry; duplicates are preserved so servers that read multi-valued headers keep behaving.
- Query strings in the URL stay in the URL; -G with --data-urlencode is promoted to a structured params argument where URLSession supports it.
- Request bodies are parsed against Content-Type: JSON bodies use idiomatic serialization (URLSession), form bodies use URL-encoding, multipart uses -F semantics with file@ handling.
- TLS flags (--insecure, --cacert, --cert) surface as inline notes so you don't ship an insecure client to production by accident.

## Common mistakes

- Forgetting that -X POST without a body still sends an empty body — the generated code mirrors that exactly.
- Assuming curl auto-follows redirects: it doesn't. Add -L (or the generator's follow-redirects flag) if you actually need to chase 3xx responses.
- Copying a Cookie header from DevTools that already encodes session state — use the Clean panel to strip session cookies before you share.

## FAQ

### How do I send a POST request in Swift?

Paste your curl POST command above. Toolpaper generates Swift using URLSession with headers, query string, and (where applicable) request body wired up.

### Does the POST generator handle authentication?

Yes — Authorization headers, Bearer tokens, Basic auth (-u), and API keys pass through to the generated Swift code unchanged.

### Is my curl sent to a server?

No. Parsing and code generation run in your browser. Nothing is uploaded.

### Can I also convert this to other languages?

Yes. Once you paste your command, the language picker lets you switch between 18 targets (fetch, axios, Python, Go, PHP, Ruby, Rust, Java, Kotlin, C#, PowerShell, Swift and more).

---

Source: https://toolpaper.manavdev.site/how-to/curl-post-in-swift · Language hub: https://toolpaper.manavdev.site/curl-to-swift