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
Example: Public Search
Client Usage
Best Practices for Public Routes
-
Input Validation
- Always validate input using Zod
- Define clear input schemas
- Handle edge cases
-
Rate Limiting
- Implement rate limiting for public endpoints
- Consider using a middleware
-
Caching
- Cache frequently accessed public data
- Use appropriate cache headers
-
Error Handling
- Return meaningful error messages
- Use appropriate HTTP status codes
Security Considerations
Even though these routes are public, you should still:- Validate all input data
- Implement rate limiting
- Sanitize output data
- Monitor for abuse
- Use HTTPS only