简体   繁体   中英

Azure API Management - Etag for an operation

We are new to Azure API management. We are caching Dataverse master entities web api calls and looking to see how we can add ETag as part of response headers in Azure API Management(Backend call doesnt have this header as well). How do we retrieve this at Operations level? and is there any reference documentation available. Sorry could not find any. Thanks in Advance

We are caching Dataverse master entities web api calls and looking to see how we can add ETag as part of response headers in Azure API Management(Backend call doesnt have this header as well). How do we retrieve this at Operations level?

  1. Get the entity state (Etag) version of the backend specified by its identifier.
HEAD https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}?api-version=2021-04-01-preview
  1. Web API implementation :
public class OrdersController : ApiController
{
    ...
    public IHttpActionResult FindOrderByID(int id)
    {
        // Find the matching order
        Order order = ...;
        ...

        var hashedOrder = order.GetHashCode();
        string hashedOrderEtag = $"\"{hashedOrder}\"";
        var eTag = new EntityTagHeaderValue(hashedOrderEtag);

        // Return a response message containing the order and the cache control header
        OkResultWithCaching<Order> response = new OkResultWithCaching<Order>(order, this)
        {
            ...,
            ETag = eTag
        };
        return response;
    }
    ...
}

You can refer to Backend - Get Entity Tag , Does Azure Search Provides Etags for managing concurrency for Add, Update or Delete Documents? and What is ETag and why people use it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM