Sample code for 30+ languages & platforms
Rust

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/azureToken.json").is_ok();
// Assuming success..
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
println!("AuthToken: {}", http.auth_token());

http.set_accept("application/json");

// Create the following JSON:

// {
//   "sku": {
//     "name": "Standard_GRS"
//   },
//   "kind": "StorageV2",
//   "location": "eastus2",
// }

// Use this online tool to generate the code from sample JSON: 
// Generate Code to Create JSON

let json_request_body = chilkat::JsonObject::new();
let _ = json_request_body.update_string("sku.name", "Standard_GRS");
let _ = json_request_body.update_string("kind", "StorageV2");
let _ = json_request_body.update_string("location", "eastus2");

let url = "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01".to_string();

let resp = chilkat::HttpResponse::new();
if http.http_json("PUT", &url, &json_request_body, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Response Status Code: {}", resp.status_code());

let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

if resp.status_code() >= 300 {
    println!("Failed.");
    return;
}

// Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously. 
// If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body.
if resp.status_code() == 202 {
    println!("Azure-AsyncOperation: {}", resp.get_header_field("Azure-AsyncOperation").unwrap_or_default());
}

if resp.status_code() == 200 {

    // Parse a response like this:

    // 	{
    // 	  "sku": {
    // 	    "name": "Standard_GRS",
    // 	    "tier": "Standard"
    // 	  },
    // 	  "kind": "StorageV2",
    // 	  "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware",
    // 	  "name": "chilkatsoftware",
    // 	  "type": "Microsoft.Storage/storageAccounts",
    // 	  "location": "eastus2",
    // 	  "tags": {},
    // 	  "properties": {
    // 	    "networkAcls": {
    // 	      "bypass": "AzureServices",
    // 	      "virtualNetworkRules": [
    // 	      ],
    // 	      "ipRules": [
    // 	      ],
    // 	      "defaultAction": "Allow"
    // 	    },
    // 	    "supportsHttpsTrafficOnly": false,
    // 	    "encryption": {
    // 	      "services": {
    // 	        "file": {
    // 	          "enabled": true,
    // 	          "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
    // 	        },
    // 	        "blob": {
    // 	          "enabled": true,
    // 	          "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
    // 	        }
    // 	      },
    // 	      "keySource": "Microsoft.Storage"
    // 	    },
    // 	    "accessTier": "Hot",
    // 	    "provisioningState": "Succeeded",
    // 
    // 	    "creationTime": "2019-05-14T22:18:33.1309165Z",
    // 	    "primaryEndpoints": {
    // 	      "dfs": "https://chilkatsoftware.dfs.core.windows.net/",
    // 	      "web": "https://chilkatsoftware.z20.web.core.windows.net/",
    // 	      "blob": "https://chilkatsoftware.blob.core.windows.net/",
    // 	      "queue": "https://chilkatsoftware.queue.core.windows.net/",
    // 	      "table": "https://chilkatsoftware.table.core.windows.net/",
    // 	      "file": "https://chilkatsoftware.file.core.windows.net/"
    // 	    },
    // 	    "primaryLocation": "eastus2",
    // 	    "statusOfPrimary": "available",
    // 	    "secondaryLocation": "centralus",
    // 	    "statusOfSecondary": "available"
    // 	  }
    // 	}

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    let sku_name = json.string_of("sku.name").unwrap_or_default();
    let sku_tier = json.string_of("sku.tier").unwrap_or_default();
    let kind = json.string_of("kind").unwrap_or_default();
    let id = json.string_of("id").unwrap_or_default();
    let name = json.string_of("name").unwrap_or_default();
    let v_type = json.string_of("type").unwrap_or_default();
    let location = json.string_of("location").unwrap_or_default();
    let properties_network_acls_bypass = json.string_of("properties.networkAcls.bypass").unwrap_or_default();
    let properties_network_acls_default_action = json.string_of("properties.networkAcls.defaultAction").unwrap_or_default();
    let properties_supports_https_traffic_only = json.bool_of("properties.supportsHttpsTrafficOnly");
    let properties_encryption_services_file_enabled = json.bool_of("properties.encryption.services.file.enabled");
    let properties_encryption_services_file_last_enabled_time = json.string_of("properties.encryption.services.file.lastEnabledTime").unwrap_or_default();
    let properties_encryption_services_blob_enabled = json.bool_of("properties.encryption.services.blob.enabled");
    let properties_encryption_services_blob_last_enabled_time = json.string_of("properties.encryption.services.blob.lastEnabledTime").unwrap_or_default();
    let properties_encryption_key_source = json.string_of("properties.encryption.keySource").unwrap_or_default();
    let properties_access_tier = json.string_of("properties.accessTier").unwrap_or_default();
    let properties_provisioning_state = json.string_of("properties.provisioningState").unwrap_or_default();
    let properties_creation_time = json.string_of("properties.creationTime").unwrap_or_default();
    let properties_primary_endpoints_dfs = json.string_of("properties.primaryEndpoints.dfs").unwrap_or_default();
    let properties_primary_endpoints_web = json.string_of("properties.primaryEndpoints.web").unwrap_or_default();
    let properties_primary_endpoints_blob = json.string_of("properties.primaryEndpoints.blob").unwrap_or_default();
    let properties_primary_endpoints_queue = json.string_of("properties.primaryEndpoints.queue").unwrap_or_default();
    let properties_primary_endpoints_table = json.string_of("properties.primaryEndpoints.table").unwrap_or_default();
    let properties_primary_endpoints_file = json.string_of("properties.primaryEndpoints.file").unwrap_or_default();
    let properties_primary_location = json.string_of("properties.primaryLocation").unwrap_or_default();
    let properties_status_of_primary = json.string_of("properties.statusOfPrimary").unwrap_or_default();
    let properties_secondary_location = json.string_of("properties.secondaryLocation").unwrap_or_default();
    let properties_status_of_secondary = json.string_of("properties.statusOfSecondary").unwrap_or_default();
}

println!("Success.");