cancel
Showing results for 
Search instead for 
Did you mean: 

UI5 Headers in payload

PedroDelgado
Explorer
0 Kudos

Hello,

I want to add custom headers in the payload of a batch. I have already achived to add it on single calls but I can't figure out how to add on eacht single call inside the payload in a Batch. Alternatively I could also just read the header of the Batch I can't find out how.

I have followed the steps here

https://blogs.sap.com/2016/07/13/set-and-get-custom-http-header/


I would like to receive it here too. Is that possible?

Thank you

Accepted Solutions (0)

Answers (3)

Answers (3)

sergei-u-niq
Active Contributor

You can add headers on model level (you shouldnt add headers to the model object if you need them only for certain requests => see suggestions by @Gurkan, like, e.g. using function imports or similar)

if, however, the whole app needs to send a certain header (for whatever reason), you can add headers in your manifest.json, e.g.

"": {
	"dataSource": "mainService",
	"preload": true,
	"settings": {
		"defaultCountMode": "Inline",
		"useBatch": true,
		"headers": {
			"foo": "bar"
		}
	}
}

which is equivalent to oModel.setHeaders({"foo":"bar"}) as described in the blog you linked. BUT, this will add headers to the batch request itself, AND to the single requests inside the batch -- just checked with current ui5 version -- but to my recollection it always has been the case

gurkanyilmaz
Explorer

To be able to receive it in there you must add them in that specific request before submitChanges method. For example this specific GET request is to the AbsenceSubtypeSet and you must add the headers as you mentioned in the link before calling model.get('/AbsenceSubtypeSet').

But if this entityset is called by table automatically you can not specify the headers before, you have to do it manually. So unbind the table in view, in specific controller call the endpoint and bind it again and so on but I think you can find another way.

Maybe you can use a function import if you want to check something from the backend instead of changing the headers.

PedroDelgado
Explorer
0 Kudos

It works indeed. I guess I made some syntax error before:

var model = this.getView().getModel();
model.setHeaders({"foo":"bar"});