Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is an example of how to make a POST request to Azure Storage REST API using Swift 5:

let urlString = "<YOUR_STORAGE_URL>"
let url = URL(string: urlString)!
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

// Set the body of the request
let body = // Your JSON body
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: [])

// Set the Authorization header with a shared access signature (SAS) token
let sas = "<YOUR_SAS_TOKEN>"
request.setValue(sas, forHTTPHeaderField: "Authorization")

let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
    if let error = error {
        print("Error: \(error)")
        return
    }

    if let data = data {
        // Process the response data
    }
}

task.resume()

Note that you will need to replace <YOUR_STORAGE_URL> with the URL for your Azure Storage account and <YOUR_SAS_TOKEN> with a shared access signature token that provides access to the resource you want to operate on (e.g., a container, blob, or queue).