Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/http/util.js>stringifyRequest

A JavaScript extension package for building strong and modern applications.
Latest
function stringifyRequest
import { stringifyRequest } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/http/util.js";

Converts the request object to text format.

Examples

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

// 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"