Prompts for Frontend Developers: copy one, fill it in, paste it into your AI.
Track progress as a memberIn this lesson
- 01Draft an API Fetch FunctionUse this when you need a starter function to call an API and handle loading and errors.
- 02Explain API Response Structure for UIUse this when you have a sample JSON response and want to understand how to map it to UI.
- 03Handle API Error StatesUse this when you need to plan user-friendly messages and retry logic for failed requests.
Draft an API Fetch Function
Use this when you need a starter function to call an API and handle loading and errors.
Role — You are a frontend developer who writes small, readable JavaScript helpers for calling APIs. Optimise for a function the reader can paste into a project and extend, with loading and error states handled.
Context you provide
- {{api_endpoint}} — URL or path to call
- {{http_method}} — GET, POST, PUT, DELETE
- {{request_body}} — fields to send, if any
- {{response_shape}} — what the API returns, or "unknown"
- {{framework}} — plain JavaScript, React, Vue, or similar
- {{error_handling_style}} — throw, return a result object, or show a message
- {{auth_requirement}} — token, API key, cookie, or none
Instructions
- Ask for any missing inputs, then write the function.
- Write one async function that builds the request with fetch, sets headers, and sends the body when the method needs one.
- Show how the caller knows a request is in flight.
- Check response.ok and surface a clear error with the status code and any message the API returns.
- Wrap the call so network failures are not left unhandled.
- Return parsed data in the shape the caller expects, and note what happens on an empty response.
- Add a short usage example showing the call and how loading and error values are read.
Output format — One code block for the function, one short code block for the usage example, then a bullet list of at most five notes. Keep comments brief. Skip any explanation of what fetch is.
Guardrails — Do not invent endpoint URLs, response fields, or auth header names; use only what the user gives. Flag any assumption about the response shape. Tell the user to check the API's own documentation for required headers, rate limits, and CORS rules.
Example — {{api_endpoint}}: /api/v1/orders, {{http_method}}: GET, {{framework}}: React, {{auth_requirement}}: bearer token.
Explain API Response Structure for UI
Use this when you have a sample JSON response and want to understand how to map it to UI.
Role You are a frontend engineer who reads API payloads closely and explains them so data can be wired into UI components without guessing.
Context you provide
- {{json_response_sample}} the response pasted exactly as received
- {{ui_target}} the screen or component that must show this data
- {{fields_needed}} the labels and values the UI must display
- {{framework}} the framework and version in use
- {{loading_error_behavior}} expected behaviour while loading and on failure
Instructions
- Ask for any missing inputs, then continue with what you have and note the gaps.
- Walk the JSON from the top: list each key, its type, and whether it is an identifier, display data, or metadata.
- For each field the UI needs, give the exact path, such as data.items[0].title, and the fallback when it is null or absent.
- Flag anything ambiguous: arrays with mixed types, dates or numbers stored as strings, pagination markers, counts that do not match array length.
- Give a mapping table from JSON path to UI element, then one short snippet in the stated framework that reads the payload and renders a single item.
- List edge cases: empty arrays, missing keys, unexpected nesting, failed requests.
Output format Short headed sections, one path-to-UI table, one snippet under 20 lines. Plain language. Leave out styling, routing, scaffolding, and library suggestions.
Guardrails
- Never invent field names, endpoints, or response shapes absent from the sample; label every assumption.
- Do not state HTTP status meanings or schema rules as fact unless the sample shows them; tell the user to confirm with their API documentation or backend owner.
- If the sample contains tokens or personal data, tell the user to redact it before sharing.
Example Sample: {"data":{"items":[{"id":7,"title":"Draft","published_at":null}]}}; target: article card in React 18; needed: title and publish status.
Handle API Error States
Use this when you need to plan user-friendly messages and retry logic for failed requests.
Role You are a frontend engineer who specialises in resilient UI states. Optimise for error handling that keeps users informed, unblocked and clear on what to do next.
Context you provide
- {{framework_and_state_layer}}: e.g. React with TanStack Query, Vue with Pinia
- {{request_or_screen}}: the call or page being hardened
- {{failure_modes}}: timeout, 401, 429, 500, offline, validation
- {{retry_constraints}}: max attempts, backoff, idempotency notes
- {{ui_surface}}: inline banner, toast, full-page state, field errors
- {{audience_and_tone}}: consumer app or internal tool, voice
- {{existing_copy_or_components}}: current strings or design system parts
Instructions
- Ask for any missing inputs, then confirm the failure modes and retry constraints before writing.
- Map each failure mode to a user-facing state: what they see, what they can do next, and whether it is retryable.
- Write the copy for each state in plain language, with no status codes or stack traces in the primary message.
- Specify retry logic: which failures auto-retry, which need a manual button, the backoff behaviour, and how duplicate submissions are prevented.
- Note the loading, empty and success states around each error so the transitions stay coherent.
- List the edge cases that need a decision, such as partial success or a session expiring mid-flow.
Output format A markdown table of failure mode, user message, action and retry behaviour, followed by a short copy block ready to paste into the codebase. Keep it under 600 words, developer-facing but plain. Leave out framework boilerplate and full component code unless asked.
Guardrails
- Do not invent status codes, error codes or API behaviour. Ask instead.
- Flag every assumption about idempotency, auth refresh or rate limits.
- Tell the user to check the API's own documentation and the design system's accessibility guidance before shipping.
Example React with TanStack Query, GET /api/orders, timeouts and 429s, 3 attempts with backoff, inline banner, consumer tone.
Skills for these tasks
Give your AI these skills and it does these tasks the expert way. Connect your AI once and it picks them up by itself.