BEGINNER • API Foundations and HTTP
Endpoint Design Lab for notifications orchestration API #6
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 { z } from "zod";
const createUserSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
role: z.enum(["user", "admin"]).default("user"),
});
export function parseCreateUser(payload: unknown) {
const result = createUserSchema.safeParse(payload);
if (!result.success) {
return {
ok: false,
error: result.error.issues.map((issue) => issue.message),
};
}
return { ok: true, data: result.data };
}
console.log("Try endpoint with:", "req.params / req.query / req.body");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.