denoland / showcase_chat

https://showcase-chat.deno.dev/
302 stars 72 forks source link

Question regarding handler #55

Open arthur-ver opened 2 years ago

arthur-ver commented 2 years ago

Hi!

I can't seem to find an example in fresh docs regarding the handler used in routes/index.tsx:

export async function handler(
  req: Request,
  ctx: HandlerContext,
): Promise<Response> {
....
}

What type of handler is this? Handlers explained in the docs (data fetching, API, middleware) look a bit different.

Thanks in advance!

With best regards, Arthur

sanderhahn commented 5 months ago

The documentation mentions at https://fresh.deno.dev/docs/getting-started/custom-handlers

To define a handler in a route module, one must export it as a named export with the name handler. Handlers can have two forms: a plain function (catchall for all HTTP methods) or a plain object where each property is a function named by the HTTP method it handles.