BEGINNER • API Foundations and HTTP
Reliability Sprint: stabilize async processing #22
This lesson targets stabilize async processing in a realistic notifications orchestration API workflow. You will practice commands: res.status(200).json(...) | req.params / req.query / req.body | npm install express. The code example is specific to backend API engineering tasks for this lesson objective.
Code Example
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export async function getAccountOverview(userId: string) {
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
subscriptions: true,
completedLessons: { take: 5, orderBy: { completedAt: "desc" } },
},
});
if (!user) {
throw new Error("User not found");
}
return {
email: user.email,
completedLessons: user.completedLessons.length,
hasSubscription: user.subscriptions.some((item) => item.status === "ACTIVE"),
};
}
console.log("Sync schema with:", "npm install express");Commands & References
- res.status(200).json(...)
- req.params / req.query / req.body
- npm install express
Lab Steps
- Prepare environment using: res.status(200).json(...)
- Implement endpoint or middleware for this scenario.
- Test positive/negative cases and inspect response contracts.
- Document one reliability or security improvement.
Exercises
- Add one edge-case validation and return clear error details.
- Improve one endpoint to be idempotent and test retries.
- Write one test case proving the expected API behavior.