Web APIs
Web APIs are a set of built-in objects and functions that allow JavaScript to interact with the browser environment. These APIs provide functionality beyond the core JavaScript language itself, enabling developers to create dynamic, interactive web applications.
Server-side runtimes like Deno are also using Web APIs over proprietary APIs. This brings multiple benefits, like easier code sharing between client and server, and browser development experience translates directly to the server.
fetch
One of the examples is the fetch API. It's used to make HTTP requests. It is implemented as specified in the WHATWG fetch spec.
It can be used in mutiple modern javascript runtimes.
async function demo() {
const response = await fetch('https://httpbin.org/get')
console.log(response.ok)
console.log(await response.json())
}
To make a POST request:
async function demo() {
const response = await fetch('https://httpbin.org/post', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({payload: 1})
})
console.log(response.ok)
console.log(await response.json())
}
More
A comprehensive list of Web APIs can be found on MDN.