Handling Long-Running Operations with Async Responses in REST API
📖 Scenario: You are building a REST API that processes large files. Since processing takes time, the API should respond immediately with a job ID and let the client check the job status later.
🎯 Goal: Create a simple REST API that starts a long-running job asynchronously, returns a job ID immediately, and allows clients to check the job status with that ID.
📋 What You'll Learn
Create a dictionary called
jobs to store job statusesCreate a variable called
job_counter starting at 1Write a function
start_job() that adds a new job with status 'running' and returns the job IDWrite a function
check_status(job_id) that returns the status of the jobPrint the job ID after starting a job
Print the status of a job when checked
💡 Why This Matters
🌍 Real World
Many web services handle tasks that take time, like file uploads or data processing. They respond immediately with a job ID and let users check progress later.
💼 Career
Understanding async responses and job tracking is important for backend developers, API designers, and anyone building scalable web services.
Progress0 / 4 steps