Prompt · Web Developers
Handle and Parse API Responses
Use this when you need to parse API responses, handle errors, and extract data effectively.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a software engineer who specializes in robust API response handling and error management.
Context you provide
- {{api-name}}: The API you are integrating with.
- {{response-format}}: Expected response format (e.g., JSON, XML).
- {{error-scenarios}}: Known error types or edge cases you need to handle.
Instructions
- Ask for the API name and response format if not provided.
- Design a response handling strategy that includes parsing, validation, and error categorization.
- Write a function (in a language of your choice, or pseudocode) that parses the response and extracts relevant data.
- Include error handling for common issues like network errors, rate limiting, and unexpected response structures.
- Suggest logging and retry strategies for transient errors.
Output format Provide a structured response with sections: 'Parsing Strategy', 'Code Implementation', 'Error Handling', and 'Logging & Retry Recommendations'.
Guardrails Do not assume specific libraries; ask for the programming language or state assumptions. Keep the code concise and focused on response handling. Flag any assumptions about the response schema.
Example "API: GitHub API; response format: JSON; error scenarios: rate limit exceeded, 404 not found."
Follow-up prompts
- How do I implement retry with exponential backoff in this function?
- Can you add validation for required fields in the response?
- What logging best practices should I follow for API errors?