cURL to Swift

curl command paste kijiye aur wahi request karne wala Swift URLSession code paayiye.

cURL to Swift aapka command browser mein hi parse karta hai. Command ke token aur credentials aapke device se bahar nahi jaate.

API client aazmaiye

cURL to Swift ke baare mein

API documentation curl bolti hai aur iOS app URLSession, aur haath se anuvaad karna wo dohraav wala kaam hai jisme chhoti galtiyan aasani se ho jaati hain — ek header chhoot gaya, body string reh gayi jabki JSON chahiye tha, ya auth flag chupchaap chhoot gaya. Ye converter curl command ko waise hi padhta hai jaise curl khud padhta hai, un flags samet jo method badalte hain ya credentials ko header mein daal dete hain, aur sirf Foundation par tika Swift deta hai. JSON body Swift dictionary banti hai jo JSONSerialization se guzarti hai.

Features

cURL to Swift kaise use karein

  1. curl command apne flags aur body ke saath paste kijiye
  2. Daayein taraf bana hua Swift padhiye
  3. Chetavniyan dekhiye ki kaunsa flag anuvaadit nahi ho paaya
  4. Code copy kijiye ya .swift file ki tarah download kijiye

Example

Input

curl https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"Ada"}'

Output

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

Method body dekh kar tay hota hai, theek waise jaise curl tay karta.

Common errors aur troubleshooting

Aksar pooche jaane wale sawaal

Kya bana hua Swift iOS, macOS aur Linux par chalega?
Haan. Wo Foundation ka URLSession istemal karta hai, jo Apple platform par aur Linux mein swift-corelibs-foundation mein hai, isliye wahi file server project mein bhi compile hoti hai.
Kya completion handler ke bajaye async/await code mil sakta hai?
Bana hua roop completion handler wali data task istemal karta hai, jo har jagah chalta hai. Use `let (data, response) = try await URLSession.shared.data(for: request)` se badalna ek line ka kaam hai.
JSON body kaise sambhala jaata hai?
Use parse karke Swift [String: Any] dictionary banaya jaata hai, phir JSONSerialization se encode. Isse payload padhne layak rehta hai aur value badalna aasan hota hai.
-b flag ki cookies ka kya hota hai?
Wo request par Cookie header ban jaati hain. Dhyaan rahe ki URLSession ka apna cookie storage hota hai jo bina alag configuration ke jod ya badal sakta hai.
Kya Swift mein badalte samay curl command upload hota hai?
Nahi. Command aapke browser mein hi parse hota hai aur code wahin banta hai — ye zaroori hai kyunki documentation aur log ke curl command mein aksar asli API key hoti hai.

Related tools

Saare ArrayKit tools