blazorhttpclientazure-table-storageetagmaui-blazor

Azure Table Http Rest Api ETag in Get request


I am working on a application with Azure Tables using Blazor Hybrid (blazor MAUI) and am using the HttpClient to send a GetAsync() request to a table URL with a querystring filter and all is great.

I send the request, get a 200 response and happily deserialise the JSON to a List of whichever object I am requesting. The query generally returns a JSON array of items as there are generally multiple applicable to the filter.

I also have implemented post methods to create new entities which work fine too.

My question is for a put/merge/delete request concurrency is managed by the ETag of the entity which I understand is passed as a response header parameter - but my objects come from a response content JSON array and thus any response header is meaningless to each object in the returned JSON array.

therefore I can only undertake a put/merge/delete action with an if-match wildcard '*' and therefore have no concurrency management.

Do I have to return a collection of partitionkey:rowkey values from my filtered get request and then iterate through them requesting individual entities so i can get the ETags asociated with them or some such?


Solution

  • Based on the documentation provided here, Etag is returned in odata.etag attribute in response body when the value of Accept request header is application/json;odata=fullmetadata. Please make sure that you have done that.

    Also, since you are deserializing the JSON response to a POCO object, you would need to ensure that odata.etag maps to a property in your POCO object. If your POCO object derives from TableEntity, then the deserialization should automatically populate ETag property.

    You may also find this link useful as well: https://learn.microsoft.com/en-us/rest/api/storageservices/payload-format-for-table-service-operations#json-format-applicationjson-versions-2013-08-15-and-later.