BEGINNER • API Foundations and HTTP
Security Drill for payments status gateway #4
This lesson targets protect sensitive operations in a realistic payments status gateway workflow. You will practice commands: curl http://localhost:3000/health | res.status(200).json(...) | req.params / req.query / req.body. The code example is specific to backend API engineering tasks for this lesson objective.
Code Example
type Job = {
id: string;
attempts: number;
maxAttempts: number;
payload: { scenario: string; action: string };
};
function processJob(job: Job) {
if (job.attempts >= job.maxAttempts) {
return { status: "dead-letter", jobId: job.id };
}
return {
status: "scheduled-retry",
nextAttempt: job.attempts + 1,
scenario: job.payload.scenario,
action: job.payload.action,
};
}
const sampleJob: Job = {
id: "job-42",
attempts: 1,
maxAttempts: 4,
payload: { scenario: "payments status gateway", action: "protect sensitive operations" },
};
console.log(processJob(sampleJob));Commands & References
- curl http://localhost:3000/health
- res.status(200).json(...)
- req.params / req.query / req.body
Lab Steps
- Prepare environment using: curl http://localhost:3000/health
- 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.