showcase_chat icon indicating copy to clipboard operation
showcase_chat copied to clipboard

Question regarding handler

Open arthur-ver opened this issue 3 years ago • 1 comments

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

arthur-ver avatar Jul 21 '22 15:07 arthur-ver

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.

sanderhahn avatar Apr 21 '24 12:04 sanderhahn