| name | fetch-api-data |
| description | This skill covers patterns for fetching and managing API data. Trigger: When working with API interactions in the frontend.
|
| license | Apache-2.0 |
| metadata | {"author":"repoforge","version":"1.0","complexity":"medium","token_estimate":350,"dependencies":[],"related_skills":[],"load_priority":"high"} |
fetch-api-data
This skill covers patterns for fetching and managing API data.
Trigger: When working with API interactions in the frontend.
Quick Reference
| Task | Pattern |
|---|
| Fetch API data | fetchApi |
| Start a generation process | startGeneration |
Critical Patterns (Summary)
- Fetch API Data: Use
fetchApi to retrieve data from the API.
- Start Generation Process: Utilize
startGeneration to initiate a data generation process.
Critical Patterns (Detailed)
Fetch API Data
Use fetchApi to retrieve data from the API, handling errors with ApiError.
import { fetchApi, ApiError } from './lib/api';
async function getData() {
try {
const data = await fetchApi('/endpoint');
console.log(data);
} catch (error) {
if (error instanceof ApiError) {
console.error('API Error:', error.message);
}
}
}
Start Generation Process
Utilize startGeneration to initiate a data generation process, allowing for real-time updates.
import { startGeneration } from './lib/api';
function initiateGeneration() {
startGeneration({ type: 'example' })
.then(response => console.log('Generation started:', response))
.catch(error => console.error('Error starting generation:', error));
}
When to Use
- When you need to fetch data from an external API.
- When initiating a data generation process that requires real-time updates.
Commands
docker-compose up
python repoforge/cli.py fetch-data
Anti-Patterns
Don't: Ignore ApiError Handling
Ignoring ApiError can lead to unhandled exceptions and poor user experience.
async function getData() {
const data = await fetchApi('/endpoint');
console.log(data);
}