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
+30-31Lines changed: 30 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,17 @@ ms.subservice: common
16
16
17
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.
18
18
19
-
## Prerequisites
19
+
## Prerequisites
20
20
21
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:
22
22
23
-
* Install [Visual Studio 2019](https://www.visualstudio.com/visual-studio-homepage-vs.aspx) with the following workload:
24
-
- Azure development
23
+
- Install [Visual Studio 2019](https://www.visualstudio.com/visual-studio-homepage-vs.aspx) with the **Azure development** workload.
25
24
26
-
* An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
25
+
- An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
27
26
28
-
* A general-purpose storage account. If you don't yet have a storage account, see [Create a storage account](storage-quickstart-create-account.md).
27
+
- A general-purpose storage account. If you don't yet have a storage account, see [Create a storage account](storage-quickstart-create-account.md).
29
28
30
-
* The example in this article shows how to list the containers in a storage account. To see output, add some containers to blob storage in the storage account before you start.
29
+
- The example in this article shows how to list the containers in a storage account. To see output, add some containers to blob storage in the storage account before you start.
31
30
32
31
## Download the sample application
33
32
@@ -61,11 +60,11 @@ Let's look at the page in the REST API Reference for the [ListContainers](/rest/
61
60
62
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.
63
62
64
-
**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`. This is created from the blob storage account endpoint `http://myaccount.blob.core.windows.net` and the resource string `/?comp=list`.
65
64
66
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.
67
66
68
-
Another helpful parameter is *maxresults:* if more containers are available than this value, the response body will contain a *NextMarker* element that indicates the next container to return on the next request. To use this feature, you provide the *NextMarker* value as the *marker* parameter in the URI when you make the next request. When using this feature, it is analogous to paging through the results.
67
+
Another helpful parameter is *maxresults:* if more containers are available than this value, the response body will contain a *NextMarker* element that indicates the next container to return on the next request. To use this feature, you provide the *NextMarker* value as the *marker* parameter in the URI when you make the next request. When using this feature, it is analogous to paging through the results.
69
68
70
69
To use additional parameters, append them to the resource string with the value, like this example:
71
70
@@ -96,17 +95,17 @@ In our sample project, the code for creating the Authorization header is in a se
96
95
97
96
To build the request, which is an HttpRequestMessage object, go to ListContainersAsyncREST in Program.cs. The steps for building the request are:
98
97
99
-
* Create the URI to be used for calling the service.
100
-
* Create the HttpRequestMessage object and set the payload. The payload is null for ListContainersAsyncREST because we're not passing anything in.
101
-
* Add the request headers for x-ms-date and x-ms-version.
102
-
* Get the authorization header and add it.
98
+
- Create the URI to be used for calling the service.
99
+
- Create the HttpRequestMessage object and set the payload. The payload is null for ListContainersAsyncREST because we're not passing anything in.
100
+
- Add the request headers for x-ms-date and x-ms-version.
101
+
- Get the authorization header and add it.
103
102
104
103
Some basic information you need:
105
104
106
-
* For ListContainers, the **method** is `GET`. This value is set when instantiating the request.
107
-
* The **resource** is the query portion of the URI that indicates which API is being called, so the value is `/?comp=list`. As noted earlier, the resource is on the reference documentation page that shows the information about the [ListContainers API](/rest/api/storageservices/List-Containers2).
108
-
* 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`.
109
-
* For ListContainers, **requestBody** is null and there are no extra **headers**.
105
+
- For ListContainers, the **method** is `GET`. This value is set when instantiating the request.
106
+
- The **resource** is the query portion of the URI that indicates which API is being called, so the value is `/?comp=list`. As noted earlier, the resource is on the reference documentation page that shows the information about the [ListContainers API](/rest/api/storageservices/List-Containers2).
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
+
- For ListContainers, **requestBody** is null and there are no extra **headers**.
110
109
111
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.
112
111
@@ -307,7 +306,7 @@ What are CanonicalizedHeaders and CanonicalizedResource? Good question. In fact,
307
306
308
307
Let's start with those two canonicalized fields, because they are required to create the Authorization header.
309
308
310
-
**Canonicalized Headers**
309
+
### Canonicalized headers
311
310
312
311
To create this value, retrieve the headers that start with "x-ms-" and sort them, then format them into a string of `[key:value\n]` instances, concatenated into one string. For this example, the canonicalized headers look like this:
@@ -433,9 +432,9 @@ The AuthorizationHeader is the last header placed in the request headers before
433
432
434
433
That covers everything you need to know to put together a class with which you can create a request to call the Storage Services REST APIs.
435
434
436
-
## How about another example?
435
+
## Example: List blobs
437
436
438
-
Let's look at how to change the code to call ListBlobs for container *container-1*. This code is almost identical to the code for listing containers, the only differences being the URI and how you parse the response.
437
+
Let's look at how to change the code to call the List Blobs operation for container *container-1*. This code is almost identical to the code for listing containers, the only differences being the URI and how you parse the response.
439
438
440
439
If you look at the reference documentation for [ListBlobs](/rest/api/storageservices/List-Blobs), you find that the method is *GET* and the RequestURI is:
441
440
@@ -463,26 +462,26 @@ foreach (XElement container in x.Element("Blobs").Elements("Blob"))
463
462
464
463
When you run this sample, you get results like the following:
465
464
466
-
**Canonicalized Headers:**
465
+
**Canonicalized headers:**
467
466
468
467
```
469
468
x-ms-date:Fri, 17 Nov 2017 05:16:48 GMT\nx-ms-version:2017-07-29\n
0 commit comments