Search code examples
odatasapui5

Add headers to the single calls in the payload


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. 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?Alternatively I could also just read the header of the Batch I can't find out how.

enter image description here


Solution

  • If you add the headers in the manifest, or using setHeaders method of the model, the header is added to batch itself and also to the single requests inside the batch. At least this is the case for v2.ODataModel implementation. not absolutely sure for ui5s implementation of the v4.ODataModel, but would assume the same. Example definition in manifest.json:

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

    had to use headers in a v4 Model yesterday. So quick update: it works the same with the only difference that the property is called httpHeaders rather than headers