Back to Supabase

Routing

apps/docs/content/guides/functions/http-methods.mdx

1.26.041.2 KB
Original Source

Overview

Edge Functions support GET, POST, PUT, PATCH, DELETE, and OPTIONS. This means you can build complete REST APIs in a single function:

tsx
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.

<Admonition type="note">

HTML content is not supported. GET requests that return text/html will be rewritten to text/plain. Edge Functions are designed for APIs and data processing, not serving web pages. Use Supabase for your backend API and your favorite frontend framework for HTML.

</Admonition>

Example

Here's a full example of a RESTful API built with Edge Functions.

<$CodeSample path="edge-functions/supabase/functions/restful-tasks/index.ts" lines={[[1, -1]]} meta="index.ts" />