Consider a Nodejs express app
I am setting a new parameter 'abc' with a string to the response object
If I send a response to frontend will they be able to view the value of abc
If you inspect via browser, you will be able to see the
- Headers
- Cookies
- Response Body etc
But is there any possibility for the value 'abc' to be got by the frontend ?
Top comments (7)
A custom key on the response object, I don't think that's how it's done.
Browser makes request, server sends response, response could headers and cookies, custom x- headers, custom cookies, or even something more exotic like server sent events or websockets, you could even inject a script into the body of the page with the values in the global scope.
Dhanush, you can add it in the header of the response or in the body of the response(classical way)
To add in the header
res.setHeader("abc", "Finding out")
To add in the body
res.status(200).json({result : "Message Successful", abc : "Finding Out"})
Hey Rajan,
Thanks for your input
I know that we can add it by setting header, but my question is if we don't add it in header & only assign the value can it be got from frontend.
No, you cannot do that. If you see the basic of Http response packet. It has header section( with several sub heading ) and a response body. These are the protocol that guide the communication between client and server.
If you are directly adding a field ( i.e. abc ) in the response , it cannot create its own section apart from what is defined in the protocol ,right?
I think this would answer you question.
Your want to send data to the frontend correct?
I don't want to send it to the frontend
I am asking like if a variable is set, is there any possibility to get the value of abc from frontend, by any means
Gotcha see above comment