cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Add response headers in SAP CAP

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos
2,218

Hi Experts,

I want to add some custom headers in response of Odata read on an entity. Is it possible in SAP Cloud application programming model (CAP)

Best Regards, Ajit

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
SAP Mentor
SAP Mentor
0 Kudos

I currently use:

req._.odataRes.setHeader
Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you Gregor 🙂

Answers (2)

Answers (2)

SebastianEsch
Active Participant
0 Kudos

In the meantime, you can avoid private APIs and use 

req.res.setHeader()

Kind regards,

Sebastian 

tobias_steckenborn
SAP Champion
SAP Champion
0 Kudos

Or access the express response object with

req._.res 

and call it's function set e.g.:

req._.res.set('field','value')

David hinted that In future (cds 6), there will be cds.context.http.{req, res} to access the express req/res object.

Best regards,

Tobias

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos

It is also working. I could mark only one as correct answer. Thank you Tobias 🙂

elmerrodriguezrd
Discoverer
0 Kudos

Hi guys, can someone provide more info?

Like a documentation link or an example?

I'm trying to change a bit my response object but Idk where.

sparsh2911
Associate
Associate
0 Kudos
Hi, could you give example for java using CdsReadEventContext