deno.land / x / manual@v1.28.2 / runtime / web_platform_apis.md
Deno aims to use web platform APIs (like fetch
) instead of inventing a new
proprietary API where it makes sense. These APIs generally follow the
specifications and should match the implementation in Chrome and Firefox. In
some cases it makes sense to deviate from the spec slightly, because of the
different security model Deno has.
Here is a list of web platform APIs Deno implements:
CustomEvent
, EventTarget
and EventListener
FormData
navigator.language
APIsetTimeout
, setInterval
, clearInterval
URL
URLPattern
URLSearchParams
WebSocket
WebGPU
You can find the Deno reference for these APIs here.
fetch
APIThe fetch
API can be used to make HTTP requests. It is implemented as
specified in the WHATWG fetch
spec.
You can find documentation about this API on MDN.
set-cookie
header on a response is not processed, or filtered from the visible response
headers.fetch
specification:3.1. 'Origin' header
.3.2. CORS protocol
.3.5. CORB
.3.6. 'Cross-Origin-Resource-Policy' header
.Atomic HTTP redirect handling
.opaqueredirect
response type.fetch
with a redirect
mode of manual
will return a basic
response
rather than an opaqueredirect
response.file:
URLs are to be handled.
Firefox is the only mainstream browser that implements fetching file:
URLs,
and even then it doesn't work by default. As of Deno 1.16, Deno supports
fetching local files. See the next section for details.request
and response
header guards are implemented, but unlike
browsers do not have any constraints on which header names are allowed.referrer
, referrerPolicy
, mode
, credentials
, cache
, integrity
,
keepalive
, and window
properties and their relevant behaviours in
RequestInit
are not implemented. The relevant fields are not present on the
Request
object.set-cookie
header is not concatenated when iterated over in the
headers
iterator. This behaviour is in the
process of being specified.As of Deno 1.16, Deno supports fetching file:
URLs. This makes it easier to
write code that uses the same code path on a server as local, as well as easier
to author code that works both with the Deno CLI and Deno Deploy.
Deno only supports absolute file URLs, this means that fetch("./some.json")
will not work. It should be noted though that if
--location
is specified, relative URLs use the
--location
as the base, but a file:
URL cannot be passed as the
--location
.
To be able to fetch some resource, relative to the current module, which would
work if the module is local or remote, you would want to use import.meta.url
as the base. For example, something like:
const response = await fetch(new URL("./config.json", import.meta.url));
const config = await response.json();
Notes on fetching local files:
--allow-read
permission is needed to be able to read a local file.GET
method, and will reject the promise
with any other method.TypeError
. This is to avoid the potential of fingerprinting attacks.CustomEvent
, EventTarget
and EventListener
The DOM Event API can be used to dispatch and listen to events happening in an application. It is implemented as specified in the WHATWG DOM spec.
You can find documentation about this API on MDN.
The TypeScript definitions for the implemented web APIs can be found in the
lib.deno.shared_globals.d.ts
and
lib.deno.window.d.ts
files.
Definitions that are specific to workers can be found in the
lib.deno.worker.d.ts
file.
Only the following APIs are implemented:
A few things that are different compared to browsers:
match()
& delete()
don't support query options yet.Version Info