Virtual Network APIs
This document provides a comprehensive reference for the Azure Virtual Network (VNet) APIs. Azure Virtual Network enables Azure resources to securely communicate with each other, with users, and with on-premises resources. VNets are the fundamental building blocks for your private network in Azure.
Core Concepts
Understanding the following core concepts is crucial before diving into the APIs:
- Subnets: A range of IP addresses within a VNet.
- Network Interfaces (NICs): Enable an Azure resource to communicate with a VNet.
- IP Addresses: Public and Private IP address configuration.
- Network Security Groups (NSGs): Filter network traffic to and from Azure resources in an Azure virtual network.
- Route Tables: Define custom routes to forward traffic to specific destinations.
- Gateways: VPN and ExpressRoute gateways for hybrid connectivity.
API Versions
The Azure Virtual Network APIs are versioned. Always specify the desired API version in your requests. Common versions include:
2020-11-012019-12-012018-08-01
Refer to the Azure documentation for the latest supported API versions.
Key API Operations
Virtual Networks
Create or Update a Virtual Network
PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}?api-version={api-version}
This operation creates a new virtual network or updates an existing one. It requires a JSON payload defining the network's address space, location, and other properties.
Request Body Example:
{
"location": "eastus",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
}
Get a Virtual Network
GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}?api-version={api-version}
Retrieves the details of a specific virtual network.
List Virtual Networks in a Resource Group
GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks?api-version={api-version}
Lists all virtual networks within a specified resource group.
Delete a Virtual Network
DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}?api-version={api-version}
Deletes a virtual network. All associated resources (like subnets) will be removed.
Subnets
Create or Update a Subnet
PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}?api-version={api-version}
Adds a new subnet to an existing virtual network or updates its properties.
Get a Subnet
GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}?api-version={api-version}
Retrieves details of a specific subnet.
List Subnets in a Virtual Network
GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets?api-version={api-version}
Lists all subnets within a specified virtual network.
Network Security Groups (NSGs)
Create or Update an NSG
PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkSecurityGroups/{networkSecurityGroupName}?api-version={api-version}
Creates or updates a network security group.
Associate NSG with a Subnet
This is typically done by updating the subnet resource to include a reference to the NSG.
PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}?api-version={api-version}
Request Body Snippet (for subnet update):
{
"properties": {
"addressPrefix": "10.0.1.0/24",
"networkSecurityGroup": {
"id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Network/networkSecurityGroups/myNsg"
}
}
}
SDKs and Tools
You can interact with the Azure Virtual Network APIs using various tools and SDKs:
- Azure CLI: Use commands like
az network vnet create,az network vnet subnet create. - Azure PowerShell: Cmdlets such as
New-AzVirtualNetwork,Add-AzVirtualNetworkSubnetConfig. - Azure SDKs: Available for .NET, Java, Python, Node.js, Go, and more.
- REST API: Direct interaction via HTTP requests.
Explore the Azure SDK documentation for detailed guidance.