Last active
June 23, 2024 23:54
-
-
Save NazCodeland/2c53255d9088d27482714edfbe847023 to your computer and use it in GitHub Desktop.
Handling multiple GET requests within one endpoint in SvelteKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CREDIT: https://github.com/karimfromjordan | |
// https://kit.svelte.dev/docs/routing#server-fallback-method-handler | |
export async function fallback({ url, request }) { | |
if (request.method === 'GET' && url.pathame === '/api/x') { | |
// ... | |
} | |
if (request.method === 'GET' && url.pathame === '/api/y') { | |
// ... | |
} | |
if (request.method === 'GET' && url.pathame === '/api/z') { | |
// ... | |
} | |
// else return error | |
} | |
// or | |
export async function GET({ url }) { | |
if (url.pathname === '/api/x') { | |
// Handle GET request for /api/x | |
} | |
if (url.pathname === '/api/y') { | |
// Handle GET request for /api/y | |
} | |
if (url.pathname === '/api/z') { | |
// Handle GET request for /api/z | |
} | |
// else return error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment