import { stringifyRequest } from "https://deno.land/x/ayonli_jsext@v0.9.72/http/util.ts";
Converts the request object to text format.
Examples
Example 1
Example 1
// GET example
import { stringifyRequest } from "@ayonli/jsext/http";
const req = new Request("http://example.com/foo");
const message = await stringifyRequest(req);
console.log(message);
// "GET /foo HTTP/1.1\r\nHost: example.com\r\n\r\n"
Example 2
Example 2
// POST example
import { stringifyRequest } from "@ayonli/jsext/http";
const req = new Request("http://example.com/foo", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "foo=hello&bar=world",
});
const message = await stringifyRequest(req);
console.log(message);
// "POST /foo HTTP/1.1\r\n" +
// "Host: example.com\r\n" +
// "Content-Type: application/x-www-form-urlencoded\r\n" +
// "Content-Length: 19\r\n" +
// "\r\n" +
// "foo=hello&bar=world"
Parameters
req: Request