Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Performing storage account operations using REST (part 3) - Creating a table using the REST API

3/13/2011 4:52:34 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

4. Creating a table using the REST API

You created a table using the following StorageClient library call:

var storageAccount =
CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["DataConnectionString"]);

CloudTableClient tableClient =
storageAccount.CreateCloudTableClient();

tableClient.CreateTableIfNotExist("ShoppingCartTable");

Ultimately the StorageClient library just wraps the REST API that’s exposed by the Table service. Let’s take a look at how this is done.

Creating a Table Using AtomPub

To create a new table, you must perform a POST request against the URI you used earlier to list and delete tables in the silverlightukstorage storage account.

POST http://silverlightukstorage.table.core.windows.net/Tables

Because the Table service implements the AtomPub protocol, the body of the POST request needs to be in the Atom document format. The following Atom document instructs the Table service to create a new table called ShoppingCartTable in the storage account:

As you can see from this verbose piece of junk, creating a simple table requires a whole bunch of useless information that’s never used.

Our two cents about the REST API method of creation

This is a complete rant, and we do apologize for it, but it has to be said. The REST API method of creating tables is unnecessarily complex and verbose. We know you probably won’t care because you’ll use the StorageClient library to create tables rather than the REST API. We also know that it’s not Microsoft’s fault—they’re just following the standard. But could we not have a simpler API call?

The method of deleting the ShoppingCartTable is pretty simple; it’s the HTTP verb DELETE with the appropriate URI, such as this one:

http://silverlightukstorage.table.core.windows.net/Tables ('ShoppingCartTable')

It’s pretty simple, isn’t it? Why does AtomPub have that mad method of creating a table? We can’t help thinking that a simpler method of creating tables would be to use the same URI as DELETE and change the HTTP verb from DELETE to POST.


Instead of using AtomPub to create tables with a crazy amount of XML, you can do the same thing with the slightly easier-to-use REST API. We’ll eventually get to the easiest way to create a table, which is with the StorageClient library.

Creating the Table Using the REST API in a Console Application

It’s time for you to create a small console application that will generate the ShoppingCartTable in a storage account using AtomPub and the REST API. The listing that follows contains the code for the console application.

Listing 2. Creating tables using the REST API and AtomPub

The console application in listing 2 is pretty much the same as the one in listing 12.1 that listed tables. But there are a few differences between the two applications. In this case, you use the URI of your table endpoint, and you need to change the HTTP verb from GET to DELETE. You also need to convert the Atom XML you used earlier from a string to a byte array. Finally, you write the Atom XML byte[] to the request body.

Over the past few sections, we’ve looked at how you can interact with the REST API directly. In each example, you’ve used the StorageClient library to sign the request, but we haven’t spent any time explaining that. Let’s take a little time out to do that now.

Other -----------------
- Performing storage account operations using REST (part 2) - Deleting tables using the REST API & WCF Data Services and AtomPub
- Doing CRUDy stuff with the Table service (part 3) - Deleting entities & Updating entities
- Doing CRUDy stuff with the Table service (part 2) - Adding entities & Listing entities
- Doing CRUDy stuff with the Table service (part 1) - Creating a context class
- Developing with the Table service
- Partitioning data across lots of servers : Partitioning the storage account & Partitioning tables
- Modifying an entity to work with the Table service
- How we’d normally represent entities outside of Azure
- A brief overview of the Table service
- BLOBs : Setting shared access permissions
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server