Deno Web APIs
Explore and test some Web APIs supported by Deno to achieve some common tasks.
We'll cover the following...
This lesson takes inspiration from an article written by Luca Casonato on Deno’s blog (see the Appendix: Further Resources for the link). Here we’ll learn some useful Deno APIs (only a small subset). Each of them, provide us a code widget to experiment with these APIs directly.
Encoding/Decoding (base64)
We can encode/decode base64 strings with the atob
and btoa
functions.
Press + to interact
const encoded = btoa("Learnind Deno is really fun!");console.log("encoded: ", encoded );const decoded = atob(encoded);console.log("decoded: ", decoded );
Encoding/Decoding (binary)
Similar to the previous two functions, we can also decode/encode strings from and into a binary representation (Uint8Array
). This is possible with the TextEncoder
and TextDecoder
APIs.
const stringToEncode = "Let's encode something with Deno!"; const textEncoder = new TextEncoder(); const encodedBytes = textEncoder.encode(stringToEncode); console.log("Encoded bytes: ", encodedBytes); const textDecoder = new TextDecoder(); const plainText = textDecoder.decode(encodedBytes); console.log("Decoded bytes into string: ", plainText);
Encoding and decoding (binary) functions
Cryptography functions
With version 1.18, Deno completely implements the Web Cryptography API. It is a standard JS ...