Compatibilidade APIs Node.js - Url

O módulo url no Node.js fornece utilitários para resolução e análise de URLs. Ele permite que os desenvolvedores trabalhem com URLs de maneira estruturada, facilitando a manipulação e a extração de informações delas. Este módulo é essencial para aplicações web que precisam lidar com URLs para roteamento, requisições de API e muito mais.

/**
* An example of using Node.js URL API in an Azion Edge Function.
* Support:
* - Partially supported (Extended by library `url`)
* @module runtime-apis/nodejs/url/main
* @example
* // Execute with Azion Bundler:
* npx edge-functions build
* npx edge-functions dev
*/
import url from "node:url";
/**
* An example of using the Node.js URL API in an Azion Edge Function.
* @param {*} event
* @returns {Promise<Response>}
*/
const main = async (event) => {
/**
* URL globalThis object
* https://developer.mozilla.org/en-US/docs/Web/API/URL
* if use URL in the browser, don't need to import
*/
const newUrl = new URL("https://example.com/some/path?format=json&page=1");
console.log("newURL", newUrl);
const urlFormated = url.format({
protocol: "https",
hostname: "example.com",
pathname: "/some/path",
query: {
page: 1,
format: "json",
},
});
console.log(url.parse(urlFormated));
return new Response("Done!", { status: 200 });
};
export default main;

Contribuidores