Fetch data

    • Like browsers, Deno implements web standard APIs such as fetch.
    • Deno is secure by default, meaning explicit permission must be granted to access the network.
    • See also: Deno’s model.
    1. /**
    2. * Receiving a file
    3. */
    4. if (fileResponse.body) {
    5. const file = await Deno.open("./logo.svg", { write: true, create: true });
    6. const writableStream = writableStreamFromWriter(file);
    7. await fileResponse.body.pipeTo(writableStream);
    8. }
    9. /**
    10. import { readableStreamFromReader } from "https://deno.land/std@$STD_VERSION/streams/mod.ts";
    11. const file = await Deno.open("./logo.svg", { read: true });
    12. const readableStream = readableStreamFromReader(file);
    13. await fetch("https://example.com/", {
    14. method: "POST",
    15. body: readableStream,
    16. });