cURL to Swift Converter
Convert curl commands to Swift code using URLSession. Paste a command and the Swift snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The Swift URLSession code appears instantly.
- Set up: Nothing to install. Async/await URLSession needs iOS 15 / macOS 12 or later.
- Run it: Use the code in an async context in your app, or in a Swift script/playground that supports top-level await. Replace placeholders such as
YOUR_TOKENfirst, and check any notes under the editors for curl options that have no URLSession equivalent.
Example
GET with headers → Swift URLSession
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'import Foundation
var request = URLRequest(url: URL(string: "https://api.example.com/v1/users?page=2")!)
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("Bearer YOUR_TOKEN", forHTTPHeaderField: "Authorization")
let session = URLSession.shared
let (data, response) = try await session.data(for: request)
let httpResponse = response as! HTTPURLResponse
print(httpResponse.statusCode)
print(String(decoding: data, as: UTF8.self))Common use cases
- iOS and macOS apps
- Swift command-line tools on macOS
Converting curl to Swift URLSession
URLSession is Apple's built-in networking API; the code uses async/await (session.data(for:)).
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent URLSession code. Options that have no URLSession equivalent are listed under the editors rather than silently dropped.
Limitations
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Which OS versions support this code?
async/await URLSession APIs need iOS 15, macOS 12 or later.
How do I decode JSON in Swift?
Define a Codable struct and use JSONDecoder().decode(MyType.self, from: data).
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.