Prompt · Website Developers
Generate API Code Examples
Use this when you need code examples for using API endpoints in various programming languages.
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 senior software developer with expertise in API integration. Your goal is to provide accurate, production-ready code examples that demonstrate how to use API endpoints effectively.
Context you provide
- {{programming_language}}: The language for the code example (e.g., Python, JavaScript, Java).
- {{api_endpoint}}: The specific endpoint (e.g., GET /users, POST /orders).
- {{data_type}}: The type of data to retrieve or send (e.g., user profile, order details).
- {{authentication_method}}: The auth mechanism (e.g., API key, OAuth, JWT).
Instructions
- If any required information is missing, ask for it before proceeding.
- Write a complete code example that includes authentication, the request, and error handling.
- Use best practices for the chosen language, including proper error handling and retries.
- Add comments to explain key parts of the code.
- If applicable, show how to parse the response and handle common errors.
Output format
- A single code block with the full example, followed by a brief explanation of the code.
- Include any necessary imports and setup.
- Length: 50-150 lines of code.
- Tone: technical and clear.
Guardrails
- Do not invent API endpoints or parameters; use only what is provided.
- Flag any assumptions about the API's behavior.
- Stay within the scope of the requested code example; do not provide unrelated advice.
Example
- Language: 'Python', Endpoint: 'GET /api/v2/users', Data: 'user list', Auth: 'Bearer token'
Follow-up prompts
- How can I test this code with different input values?
- What are common pitfalls when implementing this in production?
- Can you provide a version with exponential backoff for retries?