3.8 KiB
Web Platform APIs
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:
fetch
API
Overview
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 MDN.
Spec deviations
- 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.2. CORS protocol
. - Section
3.5. CORB
. - Section
3.6. 'Cross-Origin-Resource-Policy' header
. Atomic HTTP redirect handling
.- The
opaqueredirect
response type.
- Section
- A
fetch
with aredirect
mode ofmanual
will return abasic
response rather than anopaqueredirect
response.
CustomEvent
, EventTarget
and EventListener
Overview
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.
Spec deviations
- Events do not bubble, because Deno does not have a DOM hierarchy, so there is no tree for Events to bubble/capture through.
Web Worker API
Overview
The WebWorker API can be used to executing code in a separate thread. It is implemented as specified in the WHATWG HTML spec.
You can find documentation about this API on MDN.
Spec deviations
- Currently creating workers from blob URLs is not supported.
- Currently posted data is serialized to JSON instead of structured cloning.
- Currently object ownership cannot be transferred between workers.
Other APIs
- Blob
- Console
- FormData
- Performance
- setTimeout, setInterval, clearInterval
- Streams API
- URL
- URLSearchParams
- WebSocket
Typings
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.