I'm currently struggling with creating a Response object and I can't seem to figure out how to pass a JSON body into it.
Do I need to generate a ReadableStream for this purpose? If so, what is the correct way to do it?
I attempted the following method:
const stream = new ReadableStream({
start(controller) {
controller.enqueue(JSON.stringify({message: 'Test'}));
},
});
new Response(stream, {
status: 304,
statusText: 'Not Modified',
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
});
Unfortunately, this approach doesn't seem to be effective.