Web APIs

fetch()

Try the free JavaScript compiler

Initiates a fetch and returns a promise for a Response. Rejects on network or policy failure, not merely an HTTP error status.

Formal Syntax & Structure

javascript syntaxjavascript
fetch(input, init?)

Parameters & Attributes

NameTypeDescription
inputstring | URL | RequestRequest target or object.
initRequestInitOptional request settings.

Return Value

Promise<Response>

Promise for the response.

Working Example

Example Snippetjavascript
(async () => {const r=await fetch("data:text/plain,hello");console.log(r.status,await r.text());})()
JavaScript Reference