Representational State Transfer (REST) APIs
are service endpoints that support different sets of HTTP operations (or methods). These HTTP
methods allow you to perform different actions for your service's resources. The az rest command
should only be used when an existing Azure CLI command isn't
available.
This article demonstrates the PUT, PATCH, GET, POST, and DELETE HTTP requests to manage Azure
Container Registry resources. The Azure Container Registry
is a managed registry service that allows you to create and maintain Azure container registries that
store container images and related artifacts.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Tips for using az rest
Here's some helpful information when working with az rest:
The az rest command automatically authenticates using the logged-in credential.
If Authorization header is not set, it attaches header Authorization: Bearer <token>, where <token> is retrieved from Microsoft Entra ID.
The target resource of the token will be derived from the --url parameter when the --url parameter starts with an endpoint from the output of the az cloud show --query endpoints command. The --url parameter required.
Use the --resource parameter for a custom resource.
If Content-Type header is not set and --body is a valid JSON string, Content-Type header will default to "application/json".
When using --uri-parameters for requests in the form of OData, make sure to escape $ in different environments: in Bash, escape $ as \$ and in PowerShell, escape $ as `$.
Use PUT to create an Azure Container Registry
Use the PUT HTTP method to create a new Azure Container Registry.
# Command format example
az rest --method put \
--url https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.ContainerRegistry/registries/<containerRegistryName>?api-version=2023-01-01-preview \
--body "{'location': '<locationName>', 'sku': {'name': '<skuName>'}, 'properties': {'adminUserEnabled': '<propertyValue>'}}"
Update your Azure Container Registry by using the PATCH HTTP request. Edit the --body parameter
with the properties you want to update. This example uses the variables set in the previous section,
and updates the SKU name ($skuName="Premium") of the Azure Container Registry.
az rest --method get \
--url https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.ContainerRegistry/registries/$containerRegistryName?api-version=2023-01-01-preview
In a PowerShell environment, add {} brackets around the containerRegistryName variable as a
question mark is an allowed character in a variable name.
az rest --method get `
--url https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.ContainerRegistry/registries/${containerRegistryName}?api-version=2023-01-01-preview
The output for GET method is the same as the one shown for PUT.
Use POST to regenerate your Azure Container Registry credentials
Use the POST HTTP request to regenerate one of the login credentials for the Azure Container
Registry created in this article.
After the request is complete, your specified Azure Container Registry credentials will be
regenerated with a new password along with your existing password (password2).
Use DELETE to delete your Azure Container Registry
Use the DELETE HTTP request to delete an existing Azure Container Registry.
az rest --method delete \
--url https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.ContainerRegistry/registries/$containerRegistryName?api-version=2023-01-01-preview
In a PowerShell environment, add {} brackets around the containerRegistryName variable as a
question mark is an allowed character in a variable name.
az rest --method delete `
--url https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.ContainerRegistry/registries/${containerRegistryName}?api-version=2023-01-01-preview
Additional az rest example for Microsoft Graph
Sometimes it helps to see an example for a different scenario, so here is an example that uses the Microsoft Graph API. To update redirect URIs for an Application, call the Update application REST API, as in this code:
# Get the application
az rest --method GET \
--uri 'https://graph.microsoft.com/v1.0/applications/b4e4d2ab-e2cb-45d5-a31a-98eb3f364001'
# Update `redirectUris` for `web` property
az rest --method PATCH \
--uri 'https://graph.microsoft.com/v1.0/applications/b4e4d2ab-e2cb-45d5-a31a-98eb3f364001' \
--body '{"web":{"redirectUris":["https://myapp.com"]}}'
Clean up resources
When you are finished with the resources created in this article, you can delete the resource group.
When you delete the resource group, all resources in that resource group are deleted.
az group delete --resource-group <resourceGroupName>
Източникът за това съдържание може да бъде намерен в GitHub, където можете също да създавате и преглеждате проблеми и да изтегляте искания. За повече информация вижте нашето ръководство за сътрудник.
Обратна връзка за Azure CLI
Azure CLI е проект с отворен код. Изберете връзка, за да предоставите обратна връзка:
Learn how to create and configure an Azure Container Registry, the process of pushing container images to Azure Container Registry and explore different authentication methods and security features for Azure Container Registry.