- Docs
- Products
- Edge Application
- Edge Functions
- Edge Functions - JavaScript Examples
- JavaScript Examples - Return JSON
Return JSON
Return a JSON directly from the Edge Function. Useful for building API or middlewares.
addEventListener("fetch", event => {
const data = {
hello: "world"
}
const json = JSON.stringify(data, null, 2)
return event.respondWith(
new Response(json, {
headers: {
"content-type": "application/json;charset=UTF-8"
}
})
)
})
Didn’t find what you were looking for? Open a support ticket.