x8core
x8core5mo ago

request body

yo. how to read request body if it's node:http server? rq.body is undefined rq.read() returns null interface of streams not working ofcourse
1 Reply
Deno AI Helper
Deno AI Helper5mo ago
Hello! It seems you're trying to read the request body in a Deno context, but you've mentioned node:http which is specific to Node.js. In Deno, if you're working with the standard HTTP server, you would typically use request.body() to get the body of the request. Here's a basic example of how you might read the request body in Deno:
import { serve } from "https://deno.land/std/http/server.ts";

const server = serve({ port: 8000 });
console.log("http://localhost:8000/");

for await (const request of server) {
const body = new TextDecoder().decode(await Deno.readAll(request.body));
console.log(body);
request.respond({ body: "Received your request!" });
}
import { serve } from "https://deno.land/std/http/server.ts";

const server = serve({ port: 8000 });
console.log("http://localhost:8000/");

for await (const request of server) {
const body = new TextDecoder().decode(await Deno.readAll(request.body));
console.log(body);
request.respond({ body: "Received your request!" });
}
In this example, request.body is a Deno.Reader from which you can read the incoming data. Please note that the advice provided here is not based on the Deno documentation and you should double-check the accuracy of this advice. If you're working with a different library or have a more specific use case, please provide additional context so I can try to assist you further.