Abram
Abram5mo ago

forward stream response from openapi to frontend

forward stream openapi by using deno backend as a middleware, how to receive and send stream to frontend ? using sse
4 Replies
Abram
Abram5mo ago
@Deno AI Helper
Deno AI Helper
Deno AI Helper5mo ago
I'm sorry, but I wasn't able to find the answer to your question in the official Deno documentation. If you could provide more details or share a specific code snippet or error message, I might be able to spot any obvious syntax errors or mistakes. Please note that any advice I give is not based on the Deno documentation, and I recommend double-checking the accuracy of the advice given. If you have a specific question or issue, feel free to share it, and I'll do my best to assist you within my capabilities.
Abram
Abram5mo ago
@Deno AI Helper how can fresh post handlers return a stream api
Deno AI Helper
Deno AI Helper5mo ago
As of my last update, the Fresh framework for Deno, which is a modern web framework, doesn't have explicit documentation on returning a Stream API directly from post handlers. However, in general, HTTP handlers in Deno can return a ReadableStream to the client. Here's a basic example of how you might return a stream from a handler in a Deno server context, but please note that this is not specific to Fresh and is not based on the Fresh documentation:
async function streamHandler(req: Request): Promise<Response> {
const stream = new ReadableStream({
start(controller) {
// You would typically generate your data here and enqueue it
controller.enqueue("data part 1");
controller.enqueue("data part 2");
controller.close();
}
});

return new Response(stream, {
headers: { "Content-Type": "text/plain" },
});
}
async function streamHandler(req: Request): Promise<Response> {
const stream = new ReadableStream({
start(controller) {
// You would typically generate your data here and enqueue it
controller.enqueue("data part 1");
controller.enqueue("data part 2");
controller.close();
}
});

return new Response(stream, {
headers: { "Content-Type": "text/plain" },
});
}
In the context of Fresh, you would need to adapt this to fit within the framework's handler structure. Since this advice is not based on the Deno documentation, please ensure to double-check the accuracy and consult the Fresh documentation or community for more specific guidance. Fresh might have its own way of handling streams that should be adhered to for best practices within the framework.
More Posts