# How to add "last modified" response header to REST API

**URL:** <https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [October 11, 2018, 1:56pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487 "2018-10-11T13:56:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 11, 2018, 1:56pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/1 "2018-10-11T13:56:57Z")

</div>

We are storing the Resourcebundle in the HIPPO CMS, and publish it through REST API, using the library plugin option.

Now to enable REST api client caching, the REST response header received need to have  
following header entries.

Cache-Control:  
Last-Modified:

We are able add the header entries through

hst:responseheaders @ path /hst:hst/hst:hosts/dev-localhost/localhost

But how can set the Last-Modified header with value of the variable/node jcr:lastModified ?

Eg:-

Last-Modified: ${jcr:lastModified}

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [October 11, 2018, 2:22pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/2 "2018-10-11T14:22:23Z")

</div>

> [@jijoma](#):
>
> We are storing the Resourcebundle in the HIPPO CMS, and publish it through REST API, using the library plugin option.

Do you use “Rest Services Setup tool” in Essentials to setup a new mount (e.g, “/api”) for resource bundle documents, creating a custom JAX-RS class like the author did [1]?  
Or are you using the Generic Content REST API explained in [2]?

Regards,

Woonsan

[1] [Creating REST endpoints | Bloomreach Developers - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://www.onehippo.org/labs/rest-resources-and-hippo-cms.html)  
[2] [https://www.onehippo.org/trails/content-rest-api/introduction.html](https://www.onehippo.org/trails/content-rest-api/introduction.html)

---

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 11, 2018, 2:24pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/3 "2018-10-11T14:24:21Z")

</div>

Thanks for the quick response,

I am using Rest Services Setup tool.

Thanks

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [October 11, 2018, 3:07pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/4 "2018-10-11T15:07:37Z")

</div>

> [@jijoma](#):
>
> I am using Rest Services Setup tool.

Actually the both (the two references) can be set up through Rest Services Setup tool. Is your REST API endpoint is from (a) Plain JAX-RS or (b) Generic Content REST API?  
If you’re not sure, you can copy and paste the json output to show the structure (not data) here. Then we will know which one you’re using.

---

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 11, 2018, 3:12pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/5 "2018-10-11T15:12:50Z")

</div>

[http://localhost:8080/site/api/documents/31336ce3-1236-41ee-a2bb-ae0912104937](http://localhost:8080/site/api/documents/31336ce3-1236-41ee-a2bb-ae0912104937)

message Body

{  
“id”: “31336ce3-1236-41ee-a2bb-ae0912104937”,  
“name”: “pdf-resources”,  
“displayName”: “pdf-resources”,  
“type”: “resourcebundle:resourcebundle”,  
“pubState”: “published”,  
“pubwfCreationDate”: “2018-10-11T11:22:58.267+01:00”,  
“pubwfLastModificationDate”: “2018-10-11T11:27:03.426+01:00”,  
“pubwfPublicationDate”: “2018-10-11T11:27:09.645+01:00”,  
“bundleId”: “pdf-resources”,  
“keys”: {  
“MSG\_VM\_DOC\_TITLE”: {  
“description”: “”,  
“default”: “ZZZZZ”  
},  
“MSG\_VM\_DOC\_AUTHOR”: {  
“description”: “”,  
“default”: “ZZZ”  
}  
}  
}

## Header

Last-Modified → jcr:lastModified (value is not substituted)

Date →Thu, 11 Oct 2018 15:10:22 GMT

Content-Type →application/json;charset=UTF-8

Transfer-Encoding →chunked

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [October 11, 2018, 5:01pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/6 "2018-10-11T17:01:04Z")

</div>

OK. You are using “Content REST API” as it shows the same structure as shown in [1].  
It provides neither the feature to set “Last-Modified” header nor dynamic resolution of the value.  
According to its technical design document [2], it uses “RestApiPipeline”. So, I think it is technically possible to inject a custom valve to determine and set any extra response headers to the pipeline. See [3] for detail.

Regars,

Woonsan

[1] [https://www.onehippo.org/library/concepts/rest/content-rest-api/document-detail-resource.html](https://www.onehippo.org/library/concepts/rest/content-rest-api/document-detail-resource.html)  
[2] [https://www.onehippo.org/library/concepts/rest/content-rest-api/technical-design.html](https://www.onehippo.org/library/concepts/rest/content-rest-api/technical-design.html)  
[3] [https://www.onehippo.org/library/concepts/hst-spring/hst-orderable-valve-support.html](https://www.onehippo.org/library/concepts/hst-spring/hst-orderable-valve-support.html)

---

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 12, 2018, 2:45pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/7 "2018-10-12T14:45:11Z")

</div>

Thanks Woonsan,

I have managed to add a Valve to the RestApiPipeline, and I can add new response header using

context.getServletResponse().addHeader(“Last-Modified”, );

I tried various options to **retrieve the last modified date for the current resource bundle , but failed!!.**

I thought the Last-Modified information would be available in

context.getRequestContext().getContentBean() , but this method returned null!!

Regards,  
Jijo

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [October 12, 2018, 3:27pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/8 "2018-10-12T15:27:33Z")

</div>

> [@jijoma](#):
>
> I have managed to add a Valve to the RestApiPipeline, and I can add new response header using
> 
> context.getServletResponse().addHeader(“Last-Modified”, );

Great!

> [@jijoma](#):
>
> I tried various options to **retrieve the last modified date for the current resource bundle , but failed!!.**
> 
> I thought the Last-Modified information would be available in
> 
> context.getRequestContext().getContentBean() , but this method returned null!!

I don’t know the detail on how Content REST API is implemented and whether or not it’s supposed to set the requestContext’s content bean. It doesn’t look implemented to support that.

You can perhaps read the UUID from the URI by `HstRequestContext#getServletRequest().getRequestURI` which probably returns something like `/site/api/documents/31336ce3-1236-41ee-a2bb-ae0912104937`. Then you can get the document’s UUID from there.

Now, read the document node by `HstRequestContext#getSession().getNodeByIdentifier()` (e.g. `getSession.getNodeByIdentifier("31336ce3-1236-41ee-a2bb-ae0912104937")`), and reads its property somehow like `org.hippoecm.repository.util.JcrUtils#getDateProperty(Node node, String propNameOfTheNode, Calendar defaultDate)`.

Regards,

Woonsan

---

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 15, 2018, 10:57am UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/9 "2018-10-15T10:57:03Z")

</div>

> [@woonsanko](#):
>
> getDateProperty

Thanks,

But on that node with id, 31336ce3-1236-41ee-a2bb-ae0912104937 has only following properties,  
[jcr:mixinTypes]  
[jcr:primaryType]  
[jcr:uuid]

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 15, 2018, 11:18am UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/10 "2018-10-15T11:18:38Z")

</div>

That’s probably the handle node. You need one of the three possible subnodes representing the published/unpublished/draft variants.

---

<div class="post-metadata">

**Author:** ![jijoma](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jijoma](https://community.bloomreach.com/u/jijoma)\
**Post date:** [October 15, 2018, 2:36pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/11 "2018-10-15T14:36:08Z")

</div>

> [@jasper.floor](#):
>
> handle node

Thanks to Both,

Now we picked the data/resource sub-node from the handle node. And this sub-node has the required property “hippostdpubwf:lastModificationDate”.

Regards,  
Jijo

---

<div class="post-metadata">

**Author:** ![Danil](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/danil/32/1047_2.png) [@Danil](https://community.bloomreach.com/u/Danil)\
**Post date:** [July 9, 2021, 12:42pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/12 "2021-07-09T12:42:03Z")

</div>

Hello everyone. I have one question a bit off the topic. The last modified date and published date are actually present in document info.  
Does somebody know how to add these values to the RESOURCE API response?

---

<div class="post-metadata">

**Author:** ![Nicholas\_Pavao](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/nicholas_pavao/32/1370_2.png) [@Nicholas\_Pavao](https://community.bloomreach.com/u/Nicholas_Pavao)\
**Post date:** [July 14, 2021, 6:09pm UTC](https://community.bloomreach.com/t/how-to-add-last-modified-response-header-to-rest-api/487/13 "2021-07-14T18:09:46Z")

</div>

For anyone viewing this later, please see [How to add "last modified date" and "publish date" to Resourse API response](https://community.bloomreach.com/t/how-to-add-last-modified-date-and-publish-date-to-resourse-api-response/2681) for the solution.
