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

Working with the Table service REST API : Querying data (part 1) - Retrieving all entities in a table using the REST API

3/17/2011 5:08:24 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

1. Retrieving all entities in a table using the REST API

In this section we’ll look at how to build a small console application that will display all the entities in the Product table. This application is similar to the one that you built earlier to list tables in storage accounts.

The base URI used to query the Products table is the same base URI you used to insert, update, and delete table entities. To return all shirts stored in the Products table in the development storage account, you would make an HTTP GET request using the following URI:

http://127.0.0.1:10002/devstoreaccount1/Products

The code in listing 1 will return all entities in the Products table and display the result in the console window.

Listing 1. Listing the entities in the Products table using the REST API

The code in listing 1 is pretty much the same code as in this listing (which listed all the tables in a storage account). The only modification you need to make to that code is to change the URI for the HTTP request at to the URI of the Products table.

The REST API call that you used to list all product entities adheres to the AtomPub protocol, so the result that’s returned to the console window will display the entities from the Products table in Atom XML format, as shown in the following listing.

Listing 2. Atom XML output from the console application in listing 1
      schemas
.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://
schemas.microsoft.com/
ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Products</title>
<id>http://127.0.0.1:10002/devstoreaccount1/Products</id>
<updated>2009-08-01T11:23:48Z</updated>
<link rel="self" title="Products" href="Products" />
<entry m:etag="W/&quot;datetime'2009-07-23T19%3A55%3A38.7'&quot;">
<id>http://127.0.0.1:10002/devstoreaccount/Products(PartitionKey='Shirts',RowKey='BlueShirt')</id>
<title type="text"></title>
<updated>2009-08-01T11:23:48Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Products" href="Product(PartitionKey='Shirts',RowKey='BlueShirt')" />
<category term="AiAChapter7Web_WebRole.Products" scheme="http://schemas.
microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Name>Blue Shirt</d:Name>
<d:Description>A Blue Shirt</d:Description>
<d:Timestamp m:type="Edm.DateTime">2009-07-23T19:55:38.7</d:Timestamp>
<d:PartitionKey>Shirts</d:PartitionKey>
<d:RowKey>BlueShirt</d:RowKey>
</m:properties>
</content>
</entry>
<entry m:etag="W/&quot;datetime'2009-07-23T19%3A13%3A28.09'&quot;">
<id>http://127.0.0.1:10002/devstoreaccount1/Products(PartitionKey='Shirts',RowKey='RedShirt')
</id>
<title type="text"></title>
<updated>2009-08-01T11:23:48Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Products" href="Product(PartitionKey='Shirts',RowKey='RedShirt')" />
<category term="AiAChapter7Web_WebRole.Products" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Name>red shirt</d:Name>
<d:Description>a red shirt</d:Description>
<d:Timestamp m:type="Edm.DateTime">2009-07-23T19:13:28.09</d:Timestamp>
<d:PartitionKey>Shirts</d:PartitionKey>
<d:RowKey>RedShirt</d:RowKey>
</m:properties>
</content>
</entry>
</feed>

The Atom XML output in listing 2 returns all entities stored in the Products table (RedShirt and BlueShirt). As you can see, the returned XML is very descriptive (and also verbose), including the name of the property, the value, and the data type.

The verbosity of the returned XML means that the returned datasets are usually pretty large. You should be careful to cache data whenever possible and return the minimum amount of data required.

The verbosity of Atom XML

Hopefully, in the future, the Windows Azure Table service team will support a less verbose serialization format, such as JSON, and will also support local data shaping (explained later on in this section). JSON would be an ideal format to support because WCF Data Services (but not the Table service implementation) already supports this method of serialization.

Using JSON would require few changes to your application code, but you’d gain large benefits in terms of reduced bandwidth. The following code shows how the previously returned Atom XML could be represented in JSON:

Products:
[
{
"Name" : "blue shirt"
"Description" : "a Blue Shirt"
"Timestamp" : "2009-07-23T19:13:28.09"
"PartitionKey" : "Shirts"
"RowKey" : "BlueShirt"}
},
{
"Name" : "red shirt"
"Description" : "A Blue Shirt"
"Timestamp" : "2009-07-23T19:13:28.09"
"PartitionKey" : "Shirts"
"RowKey" : "RedShirt"}
},
]

As you can see, the JSON representation is much more readable and terse, meaning that the size of the returned documents would be greatly reduced and will therefore improve the speed of your application. Hopefully this will be supported in future versions of the Table service.

Other -----------------
- Working with the Table service REST API - Batching data
- Modifying entities with the REST API is CRUD (part 3) - Updating entities
- Modifying entities with the REST API is CRUD (part 2) - Deleting entities
- Modifying entities with the REST API is CRUD (part 1) - Inserting entities
- Working with the Table service REST API - Authenticating requests against the Table service
- Content delivery networks
- Using BLOB storage as a media server (part 3) - A Silverlight-based chunking media player
- Using BLOB storage as a media server (part 2) - A WPF-based adaptive-streaming video player
- Using BLOB storage as a media server (part 1) - Building a Silverlight or WPF video player
- Hosting Silverlight applications in BLOB storage (part 2) - Communicating with third-party sites
 
 
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