cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
424
Views
0
Helpful
5
Replies

IOS XE RESTCONF Entity Tag

Daniele Rossi
Level 1
Level 1

Hi everyone,
I have tried some RESTCONF requests on a Catalyst 9300 with IOS XE 17.3.1, all the responses have the ETag header except the GET. For what reason?

 

Thank you,

Daniele

5 Replies 5

Alex Stevenson
Cisco Employee
Cisco Employee

 

Hello @Daniele Rossi,

 

According to the MDN Web Docs on ETags - if the resource at a given URL changes, a new ETag value must be generated. As I understand it, POST, PUT or DELETE requests change what’s at the other end (either by creating, updating or destroying), and thus need an ETAg, but a GET would not change anything. This would explain why only the GET requests do not require the ETag.

 

However, according to the RESTCONF Protocol Draft from the IETF, GET requests often do contain ETags. This has has to do with some complicated interactions between the Last-Modified, ETag, If-Match, If-Modified-Since and If-Unmodified-Since headers. 

 

RESTCONF Request Headers

 

Name Description
Accept Response Content-Types that are acceptable
Content-Type The media type of the request body
Host The host address of the server
If-Match Only perform the action if the entity matches ETag
If-Modified-Since Only perform the action if modified since time
If-Unmodified-Since Only perform the action if un-modified since time

 

RESTCONF Response Headers

 

Name Description
Allow Valid actions when 405 error returned
Cache-Control The cache control parameters for the response
Content-Type The media type of the response body
Date The date and time the message was sent
ETag An identifier for a specific version of a resource
Last-Modified The last modified date and time of a resource
Location The resource identifier for a newly created resource

 

It states:

 

Since the datastore contents change at unpredictable times, responses from a RESTCONF server generally SHOULD NOT be cached.

The server SHOULD include a "Cache‑Control" header in every response that specifies whether the response should be cached. A "Pragma" header specifying "no‑cache" MAY also be sent in case the "Cache‑Control" header is not supported.

Instead of using HTTP caching, the client SHOULD track the "ETag" and/or "Last‑Modified" headers returned by the server for the datastore resource (or data resource if the server supports it). A retrieval request for a resource can include the "If‑None‑Match" and/or "If‑Modified‑Since" headers, which will cause the server to return a "304 Not Modified" Status-Line if the resource has not changed. The client MAY use the HEAD method to retrieve just the message headers, which SHOULD include the "ETag" and "Last‑Modified" headers, if this meta-data is maintained for the target resource.

 

That IETF doc isn't too long and it reads nicely for a doc. If you want to understand the intricacies, you can have a read.

 

Hope this helps!

Hi @Alex Stevenson ,
Thanks for the reply. I have read the RESTCONF Protocol Draft from the IETF and from what I understand the GET should return an ETag linked to the resource or if a specific ETag is not maintained for each resource the one associated with the Datastore should be returned. The ETag mechanism is not only enabling to implement conditional requests when caching is not possible (as you pointed out), but also to implement optimistic concurrency control (in RESTCONF the only concurrency control is based on ETag, while in NETCONF it is possible to lock the database). To do this, it would be important to have the ETags of the resources even in GET as shown in the attached image.
Best regards,

Daniele

 

Hey @Daniele Rossi,

 

Cool stuff.

 

Maybe something is off in the way the request is being made? I'm wondering if it could be something with the parameters. In this presentation from Cisco Live, Coding 1001: REST APIs, there are two GET request examples. 

 

One, does not return an ETag in the response header - Page 16

 

The other, does, return the ETag in the response header - Pages 22-23

 

 

What was different in one that made the ETag be included or left out? It could be a number of things, including the parameters, the API itself or the method used to call the request (cURL vs. Postman, etc.). 

 

I would try adjusting the parameters and the method used to call the API and see if you can get the ETag to show up in the GET request. Try both HTTP and HTTPS if you can.

 

Hope this helps!

 

 

 

Hi @Alex Stevenson,

i did some tests with cURL, postman and some browsers as client but i was not able to get eTag. I have not been able to run RESTCONF on a simple http (is this possible?)

Daniele

Hi @Daniele Rossi,

 

Hmmm.

 

Yes, RESTCONF is HTTPs or HTTP:

 

RESTCONF runs over HTTP or HTTPS. The following commands must be enabled to support RESTCONF over the respective ports:

 
ip http server
ip http secure-server

 

source: https://developer.cisco.com/docs/standard-network-devices/#!enabling-restconf-on-ios-xe/httphttps