You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/storage/common/storage-rest-api-auth.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: Calling Azure Storage Services REST API operations with Shared Key authorization | Microsoft Docs
2
+
title: Calling Azure Storage REST API operations with Shared Key authorization | Microsoft Docs
3
3
description: Use the Azure Storage REST API to make a request to Blob storage using Shared Key authorization.
4
4
services: storage
5
5
author: tamram
6
6
7
7
ms.service: storage
8
8
ms.topic: conceptual
9
-
ms.date: 08/19/2019
9
+
ms.date: 10/01/2019
10
10
ms.author: tamram
11
11
ms.reviewer: cbrooks
12
12
ms.subservice: common
13
13
---
14
14
15
15
# Using the Azure Storage REST API
16
16
17
-
This article shows you how to use the Blob Storage Service REST APIs and how to authorize the call to the service. It's written from the point of view of a developer who knows nothing about REST and no idea how to make a REST call. We look at the reference documentation for a REST call and see how to translate it into an actual REST call – which fields go where? After learning how to set up a REST call, you can leverage this knowledge to use any of the other Storage Service REST APIs.
17
+
This article shows you how to call the Azure Storage REST APIs, including how to form the Authorization header. It's written from the point of view of a developer who knows nothing about REST and no idea how to make a REST call. After you learn how to call a REST operation, you can leverage this knowledge to use any other Azure Storage REST operations.
18
18
19
19
## Prerequisites
20
20
21
-
The application lists the containers in blob storage for a storage account. To try out the code in this article, you need the following items:
21
+
The sample application lists the blob containers for a storage account. To try out the code in this article, you need the following items:
22
22
23
23
- Install [Visual Studio 2019](https://www.visualstudio.com/visual-studio-homepage-vs.aspx) with the **Azure development** workload.
24
24
@@ -32,35 +32,35 @@ The application lists the containers in blob storage for a storage account. To t
32
32
33
33
The sample application is a console application written in C#.
34
34
35
-
Use [git](https://git-scm.com/) to download a copy of the application to your development environment.
35
+
Use [git](https://git-scm.com/) to download a copy of the application to your development environment.
This command clones the repository to your local git folder. To open the Visual Studio solution, look for the storage-dotnet-rest-api-with-auth folder, open it, and double-click on StorageRestApiAuth.sln.
42
42
43
-
## What is REST?
43
+
## About REST
44
44
45
-
REST means*representational state transfer*. For a specific definition, check out [Wikipedia](https://en.wikipedia.org/wiki/Representational_state_transfer).
45
+
REST stands for*representational state transfer*. For a specific definition, check out [Wikipedia](https://en.wikipedia.org/wiki/Representational_state_transfer).
46
46
47
-
Basically, REST is an architecture you can use when calling APIs or making APIs available to be called. It's independent of what's happening on either side, and what other software is used when sending or receiving the REST calls. You can write an application that runs on a Mac, Windows, Linux, an Android phone or tablet, iPhone, iPod, or web site, and use the same REST API for all of those platforms. Data can be passed in and/or out when the REST API is called. The REST API doesn't care from what platform it's called – what's important is the information passed in the request and the data provided in the response.
47
+
REST is an architecture that enables you to interact with a service over an internet protocol, such as HTTP/HTTPS. REST is independent of the software running on the server or the client. The REST API can be called from any platform that supports HTTP/HTTPS. You can write an application that runs on a Mac, Windows, Linux, an Android phone or tablet, iPhone, iPod, or web site, and use the same REST API for all of those platforms.
48
48
49
-
Knowing how to use REST is a useful skill. The Azure product team frequently releases new features. Many times, the new features are accessible through the REST interface. Sometimes, though, the features haven't surfaced through **all** of the storage client libraries or the UI (such as the Azure portal). If you always want to use the latest and greatest, learning REST is a requirement. Also, if you want to write your own library to interact with Azure Storage, or you want to access Azure Storage with a programming language that does not have an SDK or storage client library, you can use the REST API.
49
+
A call to the REST API consists of a request, which is made by the client, and a response, which is returned by the service. In the request, you send a URL with information about which operation you want to call, the resource to act upon, any query parameters and headers, and depending on the operation that was called, a payload of data. The response from the service includes a status code, a set of response headers, and depending on the operation that was called, a payload of data.
50
50
51
51
## About the sample application
52
52
53
-
The sample application lists the containers in a storage account. Once you understand how the information in the REST API documentation correlates to your actual code, other REST calls are easier to figure out.
53
+
The sample application lists the containers in a storage account. Once you understand how the information in the REST API documentation correlates to your actual code, other REST calls are easier to figure out.
54
54
55
55
If you look at the [Blob Service REST API](/rest/api/storageservices/Blob-Service-REST-API), you see all of the operations you can perform on blob storage. The storage client libraries are wrappers around the REST APIs – they make it easy for you to access storage without using the REST APIs directly. But as noted above, sometimes you want to use the REST API instead of a storage client library.
56
56
57
57
## REST API Reference: List Containers API
58
58
59
-
Let's look at the page in the REST API Reference for the [ListContainers](/rest/api/storageservices/List-Containers2) operation. This information will help you understand where some of the fields come from in the request and response.
59
+
Take a look at the page in the REST API Reference for the [ListContainers](/rest/api/storageservices/List-Containers2) operation. This information will help you understand where some of the fields come from in the request and response.
60
60
61
61
**Request Method**: GET. This verb is the HTTP method you specify as a property of the request object. Other values for this verb include HEAD, PUT, and DELETE, depending on the API you are calling.
62
62
63
-
**Request URI**: `https://myaccount.blob.core.windows.net/?comp=list`. This is created from the blob storage account endpoint `http://myaccount.blob.core.windows.net` and the resource string `/?comp=list`.
63
+
**Request URI**: `https://myaccount.blob.core.windows.net/?comp=list`. The request URI is created from the blob storage account endpoint `http://myaccount.blob.core.windows.net` and the resource string `/?comp=list`.
64
64
65
65
[URI parameters](/rest/api/storageservices/List-Containers2#uri-parameters): There are additional query parameters you can use when calling ListContainers. A couple of these parameters are *timeout* for the call (in seconds) and *prefix*, which is used for filtering.
66
66
@@ -89,7 +89,7 @@ This field is an XML structure providing the data requested. In this example, th
89
89
90
90
## Creating the REST request
91
91
92
-
A couple of notes before starting – for security when running in production, always use HTTPS rather than HTTP. For the purposes of this exercise, you should use HTTP so you can view the request and response data. To view the request and response information in the actual REST calls, you can download [Fiddler](https://www.telerik.com/fiddler) or a similar application. In the Visual Studio solution, the storage account name and key are hardcoded in the class. The ListContainersAsyncREST method passes the storage account name and storage account key to the methods that are used to create the various components of the REST request. In a real world application, the storage account name and key would reside in a configuration file, environment variables, or be retrieved from an Azure Key Vault.
92
+
For security when running in production, always use HTTPS rather than HTTP. For the purposes of this exercise, you should use HTTP so you can view the request and response data. To view the request and response information in the actual REST calls, you can download [Fiddler](https://www.telerik.com/fiddler) or a similar application. In the Visual Studio solution, the storage account name and key are hardcoded in the class. The ListContainersAsyncREST method passes the storage account name and storage account key to the methods that are used to create the various components of the REST request. In a real world application, the storage account name and key would reside in a configuration file, environment variables, or be retrieved from an Azure Key Vault.
93
93
94
94
In our sample project, the code for creating the Authorization header is in a separate class. The idea is that you could take the whole class and add it to your own solution and use it "as is." The Authorization header code works for most REST API calls to Azure Storage.
95
95
@@ -107,38 +107,38 @@ Some basic information you need:
107
107
- The URI is constructed by creating the Blob service endpoint for that storage account and concatenating the resource. The value for **request URI** ends up being `http://contosorest.blob.core.windows.net/?comp=list`.
108
108
- For ListContainers, **requestBody** is null and there are no extra **headers**.
109
109
110
-
Different APIs may have other parameters to pass in such as *ifMatch*. An example of where you might use ifMatch is when calling PutBlob. In that case, you set ifMatch to an eTag, and it only updates the blob if the eTag you provide matches the current eTag on the blob. If someone else has updated the blob since retrieving the eTag, their change won't be overridden.
110
+
Different APIs may have other parameters to pass in such as *ifMatch*. An example of where you might use ifMatch is when calling PutBlob. In that case, you set ifMatch to an eTag, and it only updates the blob if the eTag you provide matches the current eTag on the blob. If someone else has updated the blob since retrieving the eTag, their change won't be overridden.
// If you need any additional headers, add them here before creating
141
-
// the authorization header.
141
+
// the authorization header.
142
142
```
143
143
144
144
Callthemethodthatcreatestheauthorizationheaderandaddittotherequestheaders. You'll see how to create the authorization header later in the article. The method name is GetAuthorizationHeader, which you can see in this code snippet:
@@ -149,15 +149,15 @@ Call the method that creates the authorization header and add it to the request
Nowthatyouhavetherequest, youcancallSendAsynctosendtheRESTrequest. SendAsynccallstheAPIandgetstheresponseback. ExaminetheresponseStatusCode (200isOK), thenparsetheresponse. Inthiscase, yougetanXMLlistofcontainers. Let's look at the code for calling the GetRESTRequest method to create the request, execute the request, and then examine the response for the list of containers.
0 commit comments