Home NewsX Performing simple Azure Table Storage REST API operations using curl command.

Performing simple Azure Table Storage REST API operations using curl command.

by info.odysseyx@gmail.com
0 comment 7 views


This blog provides instructions on how to perform simple Table storage REST API operations such as create table, drop table, insert entity, delete entity, merge entity, get table properties, get table store statistics, query table, query entity, and update entity operations using curl commands.

We will look at some command syntax for performing REST API operations and will use SAS token as an authentication mechanism. You will need to take care of the pointers below while performing the operations via curl command.

  • Make sure the URL is correctly structured for the task you are trying to perform.
  • Required headers must be passed with correct values.
  • You need to add or remove unnecessary ‘?’ from SAS tokens in your URL.
  • The HTTP verb can be GET, PUT or DELETE, depending on the REST API specification.

So, shall we begin?

  1. Get table storage properties:

This Rest API gets the properties of an Azure Table Storage account. Here is the reference link for the Rest API.

Get Table Service Properties (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X GET "https://.table.core.windows.net/?restype=service&comp=properties" -H "x-ms-date:2024-02-23T03:24Z" -H "x-ms-version:2020-04-08"

calculation:

ShraddhaSwadi_0-1724391575801.png

  1. Get table storage statistics:

This Rest API retrieves statistics related to replication in Azure Table Storage. This operation only works on: 2nd location end point If RAGRS replication is enabled for the storage account. Reference links: Get Table Service Statistics (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X GET "https://storageaccount-secondary.table.core.windows.net/?restype=service&comp=stats&” -H "x-ms-date:2024-02-23T03:24Z" -H "x-ms-version:2020-04-08"

calculation:

ShraddhaSwadi_1-1724391575806.png

  1. question table:
    This Rest API returns a list of tables under a specified account. Reference Link:
    Query Tables (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X GET "https://storageaccount.table.core.windows.net/Tables?" -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08"

calculation:

ShraddhaSwadi_2-1724391575829.png

  1. Create a table:

This Rest API creates a new table in a storage account. Reference links: Create Table (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X POST "https://storageaccount.table.core.windows.net/Tables? " -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08" -H "Content-Length: 27" -H "Content-Type: application/json" -d "{\"TableName\":\"sampletable\"}

calculation:

ShraddhaSwadi_3-1724391575842.png

ShraddhaSwadi_4-1724391575847.png

  1. Delete table:
    This Rest API deletes a table from a storage account. Reference links: Delete Table (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X DELETE "https://storageaccount.table.core.windows.net/Tables('sampletable')? " -H "x-ms-date:2024-02-23T18:16:35Z" -H "x-ms-version:2020-04-08" -H "Content-Type: application/json"


calculation:

ShraddhaSwadi_5-1724391575849.png

ShraddhaSwadi_6-1724391575853.png

  1. Entity query:
    This Rest API queries entities in a table and includes $filter and $select options. Reference links: Entity Query (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X GET "https://storageaccount.table.core.windows.net/shswadsampletable1(PartitionKey='B',RowKey='1')? " -H "x-ms-date:2024-02-24T10:14:50.2646880Z" -H "x-ms-version:2020-04-08"


calculation:

ShraddhaSwadi_7-1724391575858.png

ShraddhaSwadi_8-1724391575863.png

  1. Delete entity operation:
    This Rest API deletes an existing entity in a table. Reference link: Delete Entity (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X DELETE "https://storageaccount.table.core.windows.net/shswadsampletable1(PartitionKey%3D'B'%2C%20RowKey%3D'1')? " -H "x-ms-date:2024-02-24T11:14:50.2646880Z" -H "x-ms-version:2020-04-08" -H "If-Match:*"


calculation:

ShraddhaSwadi_9-1724391575864.png

ShraddhaSwadi_10-1724391575868.png

  1. Insert operation:

This Rest API inserts a new entity into a table. Reference links: Insert Entity (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X POST "https://storageaccount.table.core.windows.net/test? " -H "x-ms-date: 2024-02-25T10:39:50.2646880Z" -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"111\"}"


calculation:

ShraddhaSwadi_11-1724391575871.png

ShraddhaSwadi_12-1724391575875.png

  1. Update task:

This Rest API updates an existing entity in Table Storage. Reference Links: Update Entity (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X PUT "https://storageaccount.table.core.windows.net/test(PartitionKey%3D'ss'%2C%20RowKey%3D'bbb')? " -H "x-ms-date: 2024-02-25T10:39:50.2646880Z" -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -H "If-Match=*" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"111\"}


calculation

ShraddhaSwadi_13-1724391575877.png

ShraddhaSwadi_14-1724391575884.png

Merge operation:
This Rest API operation updates an existing entity by updating the properties of the entity and does not replace the existing entity. Reference links: Merge Entities (REST API) – Azure Storage | Microsoft Learn

Syntax URL:

curl -X PUT "https://storageaccount.table.core.windows.net/test(PartitionKey%3D'ssss'%2C%20RowKey%3D'bbb')? " -H "x-ms-version: 2020-04-08" -H "Accept: application/json;odata=nometadata" -H "Content-Type: application/json" -H "If-Match=*" -d "{\"RowKey\":\"bbb\",\"PartitionKey\":\"ssss\",\"Name\":\"aaa\",\"PhoneNumber\":\"11231\"}"


calculation:

ShraddhaSwadi_15-1724391575886.png

ShraddhaSwadi_16-1724391575890.png

I hope this article will help you perform table save operations using the curl command.

Have fun learning!





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX