Hi all, I need to persist this variable across multiple request methods. I only have access to it in GET and need to persist it to be used in the following POST request.
Here is the code...
In the GET method, I need access to variable "hi", which returns undefined. Obviously because its out of scope but I need it to be declared in the POST (as I'm getting the actual request from the POST request body)
A few things to note:
- I need data from the post request body in future requests, so it can't be declared elsewhere
- Because of a technical limitation of what I'm working with, they do need to be separate statements (can't be strung together with || or otherwise)
export default function handler(req, res) {
if(req.method === 'POST') {
var hi = req.body
}
if (req.method === 'GET') {
console.log(hi)
}
}
Thanks in advance!