API & Backend
Code Review: Inefficient API Implementation
easyCode ReviewJS / TS
Problem Statement
Review the following search API route handler. Identify unnecessary work, missing database pagination, over-fetching raw data, and security exposures.
Code under review
JAVASCRIPT• handler.js
Pairlet Snippet
// API route GET /api/users/search?q=name
async function searchUsersHandler(req, res) {
const searchQuery = req.query.q || "";
const allUsers = await db.query('SELECT * FROM users');
const matchedUsers = allUsers.filter(u =>
u.name.toLowerCase().includes(searchQuery.toLowerCase())
);
return res.json({
total: matchedUsers.length,
users: matchedUsers
});
}
Read only. Write down what you would flag below, then compare with the reference notes.
JavaScript & TypeScript versions included
Run this as a live interviewPractice solo
Write down what you would flag in this code, then compare it with the reference notes.
Write your findings first, then check yourself against the notes.