Search code examples
typescriptsveltesveltekit

SvelteKit: Is there a way to create multiple GET endpoints in a single +server.js file?


This is an example of what i'm trying to achieve... I'm wondering if there is something like this in sveltekit without creating a separate file to handle the "GET_2" endpoint.

// +server.ts
export const GET: RequestHandler = async () => {
  // ...stuff
};


export const GET_2: RequestHandler = async () => {
  // ...stuff
};


Solution

  • To my knowledge that is not possible, the +server documentation merely states that for each HTTP method of GET, POST, PATCH, PUT and DELETE a handler can be exported.

    You could work around that by using query parameters and then delegating to corresponding functions in the file.