Design dedicated API endpoints for data that changes frequently or grows over time, rather than hardcoding such information in frontend files. This pattern ensures that applications remain maintainable as backend data evolves.
Design dedicated API endpoints for data that changes frequently or grows over time, rather than hardcoding such information in frontend files. This pattern ensures that applications remain maintainable as backend data evolves.
When to apply:
Example: Instead of:
// ui/lib/lighthouse/helpers/complianceframeworks.ts
export const complianceFrameworks = {
aws: [
{ id: "cis-aws", name: "CIS AWS Benchmark" },
{ id: "aws-foundational", name: "AWS Foundational Security Best Practices" },
// Adding new frameworks requires code changes and deployment
]
};
Implement an API endpoint:
// API service
app.get('/api/compliance-frameworks/:provider', (req, res) => {
const provider = req.params.provider;
return res.json(getComplianceFrameworksByProvider(provider));
});
// Frontend usage
const fetchFrameworks = async (provider) => {
const response = await fetch(`/api/compliance-frameworks/${provider}`);
return await response.json();
};
This approach eliminates maintenance overhead when adding new frameworks and allows for dynamic filtering and presentation options.
Enter the URL of a public GitHub repository