How to send additional data which is not part of the entity to the backend (eg. via an URL query)

I want to send additional information from my SAPUI5 frontend to my CAP backend via the OData V2 protocol. These information are not part of the entity the request is send to. How can I solve this?

I already tried adding the urlParameters property of the ODataModel.create method. This seems to work regarding the outgoing request URL (I'm using batch requests):

POST Requirements?amount=1 HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: de
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 346

{<Body>}

However, I can't find them in my backend. There I'm using the srv.before request handler but I can't find a way to access the query:

module.exports = async function (srv) {

    srv.before("CREATE", "Requirements", req => {
        console.log("Request query", req._.req.query); // output: {}
    });
}

Do you have any suggestions how to solve this?



Read more here: https://stackoverflow.com/questions/67004899/how-to-send-additional-data-which-is-not-part-of-the-entity-to-the-backend-eg

Content Attribution

This content was originally published by MXMLNDML at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: