Free web tool
cURL to Swift
Paste a cURL command, from API docs or your browser’s “Copy as cURL”, and get Swift URLRequest code you can drop into an app.
Runs in your browser. Nothing you paste is uploaded.
What gets converted
- Method from
-X, or worked out the way cURL does:POSTwhen there is data,HEADfor-I. - Headers from
-H, plus-A,-e(referer) and-r(range). - Body from
-d,--data-raw,--data-binary,--data-urlencodeand--json, including the content type cURL adds for you. - Cookies from
-b, and credentials from-uand--oauth2-bearer. - Query data moved into the URL by
-G, and the timeout from-m.
Options that only change how cURL prints or saves its output, such as -s, -v and -o, are skipped. Anything that can’t be converted, such as multipart uploads with -F, is listed above the code so nothing is dropped silently.
Questions
Is my command, with its tokens and cookies, sent anywhere?
No. The conversion happens in your browser and nothing you paste is uploaded.
Which Swift version does the output need?
The async/await version needs Swift 5.5 and iOS 15, macOS 12 or later. The completion-handler version uses if let shorthand from Swift 5.7 and runs on any OS that has URLSession.
Why does the body use a string that starts with #"?
That is a Swift raw string. JSON is full of quotes, and a raw string lets it appear as written without a backslash before each one.
When should I build the URL with URLComponents?
When parts of the URL come from variables. URLComponents percent-encodes each query value for you, which string concatenation doesn’t.
The app
These tools, on every Apple device you own.
URL Components adds an editor that rebuilds the request as you type, a share sheet extension, a saved history, converters for JWT, Base64 and JSON, and Swift, cURL and JavaScript you can copy in one tap.
Free on iPhone, iPad and Mac. Requires iOS 17 or macOS 14.