cURL to Objective-C Converter
Convert curl commands to Objective-C code using NSURLSession. Paste a command and the Objective-C 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 Objective-C NSURLSession code appears instantly.
- Set up: Nothing to install — it's part of Foundation.
- Run it: Compile with
clang -fobjc-arc -framework Foundation request.m -o requestand run./request, or use the code in your Xcode project. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no NSURLSession equivalent.
Example
GET with headers → Objective-C NSURLSession
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
@autoreleasepool {
NSURL *url = [NSURL URLWithString:@"https://api.example.com/v1/users?page=2"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"Bearer YOUR_TOKEN" forHTTPHeaderField:@"Authorization"];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"%ld", (long)httpResponse.statusCode);
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
dispatch_semaphore_signal(semaphore);
}];
[task resume];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
return 0;
}Common use cases
- Existing Objective-C iOS and macOS apps
Converting curl to Objective-C NSURLSession
NSURLSession is Apple's Foundation API for HTTP on macOS and iOS.
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 NSURLSession code. Options that have no NSURLSession 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
Why the semaphore?
It keeps a command-line program running until the asynchronous request finishes. In an app, handle the result in the completion block instead.
Is there a Swift version?
Yes — see cURL to Swift.
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.