Introduction
Edge Functions run code close to users to handle tasks securely and quickly on the server side.
Edge Functions run code close to users to handle tasks securely and quickly on the server side.
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; serve((request) => { // Your server-side logic here return new Response('Hello from Edge Function'); });
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; serve((request) => { return new Response('Hello World'); });
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; serve(async (request) => { const data = await fetch('https://api.example.com/data'); const json = await data.json(); return new Response(JSON.stringify(json), { headers: { 'Content-Type': 'application/json' } }); });
This Edge Function simulates server-side logic by creating a user object and returning a personalized greeting.
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; serve((request) => { const user = { id: 1, name: 'Alice' }; // Simulate server-side logic like authentication or data fetching const message = `Hello, ${user.name}! This message is from the server.`; return new Response(message, { headers: { 'Content-Type': 'text/plain' } }); });
Edge Functions run outside the user's browser, so they keep secrets safe.
They help make apps faster by running code near the user.
Always keep your server-side logic in Edge Functions to protect data and improve performance.
Edge Functions run server-side code close to users for speed and security.
They handle tasks like data processing, authentication, and API calls.
Using Edge Functions helps keep sensitive logic safe and apps responsive.
export default async function handler(req) {
const user = { id: 1, name: 'Alice' };
return new Response(JSON.stringify(user), { headers: { 'Content-Type': 'application/json' } });
}export default async function handler(req) {
const data = await fetch('https://api.example.com/data');
return data.json();
}Pass the test and this pattern moves unknown