Example 1 — Quick demo
Core usage.
JavaScript
const res = new Response(JSON.stringify({ a: 1 }), {
status: 200,
headers: { "Content-Type": "application/json" }
});
console.log(res.ok);
res.json().then((d) => console.log(d.a));How It Works
- new Response. Useful for mocks and service workers.
- ok / json(). Same as fetch results.
