Senior
Design an API for generating a bank statement (PDF document, which takes a long time to generate). What endpoints are needed?
sobes.tech AI
Answer from AI
For the API generating bank statements, considering that PDF generation can take a long time, it is recommended to use an asynchronous approach with multiple endpoints:
-
POST /statements/generate
- Request to create a new statement.
- The request body includes parameters: period, account, filters, etc.
- Returns a unique
statementIdand a status of "processing".
-
GET /statements/{statementId}/status
- Check the status of the statement generation.
- Returns status: "processing", "ready", "error".
-
GET /statements/{statementId}/download
- Download the ready PDF.
- Returns the file if the status is "ready".
-
DELETE /statements/{statementId} (optional)
- Delete the generated statement to free up space.
This approach allows the client not to wait for the generation to complete, but to poll the status and download the file when it is ready.