Overview
Edge Functions support GET, POST, PUT, PATCH, DELETE, and OPTIONS. This means you can build complete REST APIs in a single function:
Deno.serve(async (req) => {
const { method, url } = req
const { pathname } = new URL(url)
// Route based on method and path
if (method === 'GET' && pathname === '/users') {
return getAllUsers()
} else if (method === 'POST' && pathname === '/users') {
return createUser(req)
}
return new Response('Not found', { status: 404 })
})
Edge Functions allow you to build APIs without needing separate functions for each endpoint. This reduces cold starts and simplifies deployment while keeping your code organized.
Example
Here's a full example of a RESTful API built with Edge Functions.
Code sample: see project quickstart in Zuvo Studio.