Skip to main content

When to Use Public Routes

Use public routes for:
  • Public data access
  • Authentication endpoints
  • Health checks
  • Public product information
  • Public API documentation
  • Public search functionality

Creating Public Routes

Example: Health Check Endpoint

Client Usage

Best Practices for Public Routes

  1. Input Validation
    • Always validate input using Zod
    • Define clear input schemas
    • Handle edge cases
  2. Rate Limiting
    • Implement rate limiting for public endpoints
    • Consider using a middleware
  3. Caching
    • Cache frequently accessed public data
    • Use appropriate cache headers
  4. Error Handling
    • Return meaningful error messages
    • Use appropriate HTTP status codes

Security Considerations

Even though these routes are public, you should still:
  1. Validate all input data
  2. Implement rate limiting
  3. Sanitize output data
  4. Monitor for abuse
  5. Use HTTPS only

Next Steps