Skip to content

Commit af9284c

Browse files
committed
clean up
1 parent d24bd4b commit af9284c

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

articles/storage/common/storage-rest-api-auth.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
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
33
description: Use the Azure Storage REST API to make a request to Blob storage using Shared Key authorization.
44
services: storage
55
author: tamram
66

77
ms.service: storage
88
ms.topic: conceptual
9-
ms.date: 08/19/2019
9+
ms.date: 10/01/2019
1010
ms.author: tamram
1111
ms.reviewer: cbrooks
1212
ms.subservice: common
1313
---
1414

1515
# Using the Azure Storage REST API
1616

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.
1818

1919
## Prerequisites
2020

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:
2222

2323
- Install [Visual Studio 2019](https://www.visualstudio.com/visual-studio-homepage-vs.aspx) with the **Azure development** workload.
2424

@@ -32,35 +32,35 @@ The application lists the containers in blob storage for a storage account. To t
3232

3333
The sample application is a console application written in C#.
3434

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.
3636

3737
```bash
3838
git clone https://github.com/Azure-Samples/storage-dotnet-rest-api-with-auth.git
3939
```
4040

4141
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.
4242

43-
## What is REST?
43+
## About REST
4444

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).
4646

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.
4848

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.
5050

5151
## About the sample application
5252

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.
5454

5555
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.
5656

5757
## REST API Reference: List Containers API
5858

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.
6060

6161
**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.
6262

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`.
6464

6565
[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.
6666

@@ -89,7 +89,7 @@ This field is an XML structure providing the data requested. In this example, th
8989

9090
## Creating the REST request
9191

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.
9393

9494
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.
9595

@@ -107,38 +107,38 @@ Some basic information you need:
107107
- 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`.
108108
- For ListContainers, **requestBody** is null and there are no extra **headers**.
109109

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.
111111

112-
First, set the `uri` and the `payload`.
112+
First, set the `uri` and the `payload`.
113113

114114
```csharp
115-
// Construct the URI. This will look like this:
115+
// Construct the URI. It will look like this:
116116
// https://myaccount.blob.core.windows.net/resource
117117
String uri = string.Format("http://{0}.blob.core.windows.net?comp=list", storageAccountName);
118118

119-
// Set this to whatever payload you desire. Ours is null because
119+
// Provide the appropriate payload, in this case null.
120120
// we're not passing anything in.
121121
Byte[] requestPayload = null;
122122
```
123123

124124
Next, instantiate the request, setting the method to `GET` and providing the URI.
125125

126-
```csharp
127-
//Instantiate the request message with a null payload.
126+
```csharp
127+
// Instantiate the request message with a null payload.
128128
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri)
129129
{ Content = (requestPayload == null) ? null : new ByteArrayContent(requestPayload) })
130130
{
131131
```
132132

133-
Add the request headers for x-ms-date and x-ms-version. This place in the code is also where you add any additional request headers required for the call. In this example, there are no additional headers. An example of an API that passes in extra headers is SetContainerACL. For Blob storage, it adds a header called "x-ms-blob-public-access" and the value for the access level.
133+
Add the request headers for `x-ms-date` and `x-ms-version`. This place in the code is also where you add any additional request headers required for the call. In this example, there are no additional headers. An example of an API that passes in extra headers is the Set Container ACL operation. This API call adds a header called "x-ms-blob-public-access" and the value for the access level.
134134

135135
```csharp
136136
// Add the request headers for x-ms-date and x-ms-version.
137137
DateTime now = DateTime.UtcNow;
138138
httpRequestMessage.Headers.Add("x-ms-date", now.ToString("R", CultureInfo.InvariantCulture));
139139
httpRequestMessage.Headers.Add("x-ms-version", "2017-07-29");
140140
// If you need any additional headers, add them here before creating
141-
// the authorization header.
141+
// the authorization header.
142142
```
143143

144144
Call the method that creates the authorization header and add it to the request headers. 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
149149
storageAccountName, storageAccountKey, now, httpRequestMessage);
150150
```
151151

152-
At this point, `httpRequestMessage` contains the REST request complete with the authorization headers.
152+
At this point, `httpRequestMessage` contains the REST request complete with the authorization headers.
153153

154154
## Call the REST API with the request
155155

156156
Now that you have the request, you can call SendAsync to send the REST request. SendAsync calls the API and gets the response back. Examine the response StatusCode (200 is OK), then parse the response. In this case, you get an XML list of containers. 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.
157157

158158
```csharp
159159
// Send the request.
160-
using (HttpResponseMessage httpResponseMessage =
160+
using (HttpResponseMessage httpResponseMessage =
161161
await new HttpClient().SendAsync(httpRequestMessage, cancellationToken))
162162
{
163163
// If successful (status code = 200),
@@ -205,7 +205,7 @@ Date: Fri, 17 Nov 2017 00:23:42 GMT
205205
Content-Length: 1511
206206
```
207207

208-
**Response body (XML):** For ListContainers, this shows the list of containers and their properties.
208+
**Response body (XML):** For the List Containers operation, this shows the list of containers and their properties.
209209

210210
```xml
211211
<?xml version="1.0" encoding="utf-8"?>

0 commit comments

Comments
 (0)