Web Platform APIs
Here is a list of web platform APIs Deno implements:
The 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 .
- The Deno user agent does not have a cookie jar. As such, the
set-cookie
header on a response is not processed, or filtered from the visible response headers. - Deno does not follow the same-origin policy, because the Deno user agent
currently does not have the concept of origins, and it does not have a cookie
jar. This means Deno does not need to protect against leaking authenticated
data cross origin. Because of this Deno does not implement the following
sections of the WHATWG
fetch
specification:- Section
3.1. 'Origin' header
. - Section
3.5. CORB
. - Section .
Atomic HTTP redirect handling
.- The
opaqueredirect
response type.
- Section
- A
fetch
with aredirect
mode ofmanual
will return abasic
response rather than anopaqueredirect
response. - The specification is vague on how
file:
URLs are to be handled. Firefox is the only mainstream browser that implements fetchingfile:
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.
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 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:
Notes on fetching local files:
- Permissions are applied to reading resources, so an appropriate
--allow-read
permission is needed to be able to read a local file. - Fetching locally only supports the
GET
method, and will reject the promise with any other method. - A file that does not exists simply rejects the promise with a vague
TypeError
. This is to avoid the potential of fingerprinting attacks. - No headers are set on the response. Therefore it is up to the consumer to determine things like the content type or content length.
- Response bodies are streamed from the Rust side, so large files are available in chunks, and can be cancelled.
You can find documentation about this API on .
- Events do not bubble, because Deno does not have a DOM hierarchy, so there is no tree for Events to bubble/capture through.
The TypeScript definitions for the implemented web APIs can be found in the
and
lib.deno.window.d.ts
files.
Definitions that are specific to workers can be found in the file.