Routing Methods in Edge Functions

For me, when I write API’s, I would seriously think about the Request HTTP Methods that I my API’s will accept carefully, because:

  1. Not to envoke my API’s with without the correct HTTP Method, If my API meant to be used with get method, I would like to block methods other than GET, HEAD.
  2. To show Appreciate content based on The Request HTTP Method, like showing GraphQL Playground with GET Method & Running the Actual GraphQL Code with POST Method.

I think Edge Functions don’t have these feature right now, but these are some approaches:

  1. File Extension Based Routing like
    hello.get.ts will run only HTTP Get Request & others respectively like hello.post.ts & more.

  2. Function based Routing like

export default function get(_request, { json }) {
  // which only runs with Http GET Requests
  return json({ hello: "world" });
}

by exporting specially named functions that corresponds with HTTP Request Methods.

  1. Config Based Routing like
[[edge_functions]]
  path = "/hello"
  function = "hello"
  method = "GET"
  # POST, PUT, ... 

I think these will reduce unnecessary envokation of Edge Functions with out the Right HTTP Request Methods & make the DX of Developing with Edge Functions Better.

Hi @amancoder28,

Thanks for the feedback. This has been passed on to the devs.

Thanks, I think these routing patterns are common & very much useful to optimize APIs & DX.