Files
awesome-reviewers/_reviewers/supabase-use-parameter-based-paths.md
2025-07-24 07:45:53 +00:00

1.6 KiB

title, description, repository, label, language, comments_count, repository_stars
title description repository label language comments_count repository_stars
Use parameter-based paths When designing API routes and interfaces, always use parameter-based path syntax instead of hardcoded literals. This approach provides better flexibility, improved type safety, and allows for more reusable code. Additionally, always validate parameters before using them in routes or API calls to prevent undefined reference errors. supabase/supabase API TSX 3 86070

When designing API routes and interfaces, always use parameter-based path syntax instead of hardcoded literals. This approach provides better flexibility, improved type safety, and allows for more reusable code. Additionally, always validate parameters before using them in routes or API calls to prevent undefined reference errors.

Example of proper path parameterization:

// Incorrect - using literal values
path: '/platform/projects/default/analytics/endpoints/logs.all'

// Correct - using parameter syntax
path: '/platform/projects/:ref/analytics/endpoints/logs.all'

Example of proper parameter validation:

// Incorrect - not validating parameter before use
if (slug === 'last-visited-org') {
  router.replace(`/new/${lastVisitedOrganization}`)
}

// Correct - validating parameter existence
if (slug === 'last-visited-org' && !!lastVisitedOrganization) {
  router.replace(`/new/${lastVisitedOrganization}`)
}

This approach also enhances API flexibility by supporting optional parameters, allowing consumers to provide only what they need. When designing component APIs, consider parameterizing inputs to increase reusability across different contexts.