Loading...
Loading...
Guide REST API integration including HTTP methods, authentication, error handling, and rate limiting. Use this skill when the user needs to connect to a third-party API, design an API client, troubleshoot API errors, or understand API concepts — even if they say 'connect to this API', 'why is the API returning errors', 'how do I authenticate', or 'build an API integration'.
npx skill4agent add asgard-ai-platform/skills tech-api-integrationIRON LAW: Read the Docs, Then Build, Then Handle Errors
1. Read the API documentation completely (auth, endpoints, rate limits, errors)
2. Get a successful request working in isolation (curl/Postman)
3. Build error handling BEFORE building features
Skipping step 1 wastes hours on trial-and-error. Skipping step 3
creates fragile integrations that break silently in production.| Method | Purpose | Idempotent? | Example |
|---|---|---|---|
| GET | Read data | Yes | |
| POST | Create new resource | No | |
| PUT | Replace entire resource | Yes | |
| PATCH | Update partial resource | Yes | |
| DELETE | Remove resource | Yes | |
| Range | Meaning | Common Codes |
|---|---|---|
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirect | 301 Moved, 304 Not Modified |
| 4xx | Client error (your fault) | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | Server error (their fault) | 500 Internal, 502 Bad Gateway, 503 Service Unavailable |
| Type | How It Works | When Used |
|---|---|---|
| API Key | Key in header or query param | Simple APIs, server-to-server |
| Bearer Token | | OAuth 2.0, JWT-based APIs |
| OAuth 2.0 | Token exchange flow (authorize → token → API call) | User-delegated access (Google, FB) |
| Basic Auth | Base64(username:password) in header | Legacy, internal APIs |
| HMAC Signature | Sign request with secret key | Payment gateways, high-security |
try:
response = api.call(request)
if response.status == 429: # Rate limited
wait(response.headers['Retry-After'])
retry()
elif response.status >= 500: # Server error
retry_with_backoff(max_retries=3)
elif response.status >= 400: # Client error
log_error(response.body)
raise ClientError(response.body['message'])
else:
return response.json()| Strategy | How |
|---|---|
Respect | Wait the specified seconds before retrying |
| Exponential backoff | Wait 1s, 2s, 4s, 8s between retries |
| Token bucket | Track request count, pause when approaching limit |
| Queue requests | Use a job queue (Celery, Bull) for high-volume integrations |
# API Integration Plan: {API Name}
## API Overview
- Base URL: {url}
- Auth: {type}
- Rate limit: {N requests/period}
- Documentation: {link}
## Endpoints Used
| Endpoint | Method | Purpose | Auth |
|----------|--------|---------|------|
| {path} | GET/POST | {what it does} | {auth type} |
## Error Handling
| Error | Response | Our Action |
|-------|----------|-----------|
| 401 | Unauthorized | Refresh token, retry |
| 429 | Rate limited | Backoff, retry after Retry-After |
| 500 | Server error | Retry 3x with exponential backoff |
## Implementation Timeline
| Phase | Task | Duration |
|-------|------|----------|
| 1 | Auth + basic call | {days} |
| 2 | Full integration | {days} |
| 3 | Error handling + monitoring | {days} |next_pageoffsetreferences/oauth-guide.mdreferences/webhook-patterns.md