conocimientoapi-integration-patternsreferences/
integration-examples.md
Referencia que api-integration-patterns carga bajo demanda desde su SKILL.md.
Detalle de los patterns, templates, examples, checklists y scripts del skill. Referencia completa para implementar integraciones con APIs externas.
Patterns (6)
- httpclient-factory.md
- IHttpClientFactory (typed/named clients)
- Configuracion en Program.cs
- Lifetime management
- Evitar socket exhaustion
- retry-policy.md
- Polly v8+ (resilience pipelines)
- WaitAndRetry con backoff exponencial
- Retry solo en errores transitorios (429, 503, timeout)
- Jitter para evitar thundering herd
- circuit-breaker.md
- Circuit breaker states (Closed, Open, Half-Open)
- Configuracion umbrales (failure rate, duracion)
- Fallback strategies
- Telemetria (logs, metrics)
- oauth2-client-credentials.md
- OAuth2 Client Credentials Flow
- Renovacion automatica de tokens
- Almacenamiento seguro (IMemoryCache)
- Azure AD / Entra ID integration
- response-caching.md
- IMemoryCache / IDistributedCache
- Cache-Control headers
- Invalidacion de cache
- Cache aside pattern
- api-versioning.md
- URL versioning (/api/v1/users)
- Header versioning (X-API-Version)
- Query string versioning (?version=1.0)
- Deprecation policies
Templates (7)
- ApiClient.cs.template
public class GenericApiClient
{
private readonly HttpClient _httpClient;
private readonly ILogger<GenericApiClient> _logger;
public async Task<ApiResponse<T>> GetAsync<T>(string endpoint)
{
// Implementacion generica
}
}
- ExternalApiClient.cs.template
- Typed HttpClient para SistemaA API
- Metodos: GetStudent(), GetCourses(), EnrollStudent()
- Autenticacion OAuth2 + API Key
- Manejo errores especificos SistemaA
- ExternalApiClient.cs.template
- Typed HttpClient para el SaaS de RRHH del catalogo
- Metodos: GetEmployees(), GetPayroll(), GetAbsences()
- Autenticacion OAuth2
- Paginacion (next links)
- ExternalApiClient.cs.template
- Typed HttpClient paral sistema de nominas
- Metodos: GetNominas(), GetEmployeePayslips()
- Autenticacion custom (API Key + HMAC)
- ApiOptions.cs.template
public class SistemaAApiOptions
{
public string BaseUrl { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public int TimeoutSeconds { get; set; } = 30;
}
- ApiResponse.cs.template
- Wrapper generico para respuestas
- Success/Error handling
- Metadata (status code, headers, elapsed time)
- DelegatingHandler.cs.template
- LoggingHandler (log request/response)
- AuthenticationHandler (inject OAuth2 token)
- CorrelationIdHandler (X-Correlation-ID)
Examples (4)
- external-api-example.md
- Caso completo: matricular estudiante
- Configuracion appsettings.json
- Registro servicios (DI)
- Uso desde Controller/Command
- Tests unitarios (MockHttpMessageHandler)
- external-api-example.md
- Caso completo: obtener empleados activos
- OAuth2 flow
- Paginacion de resultados
- Cache de respuestas (IMemoryCache)
- external-api-example.md
- Caso completo: obtener nominas del mes
- Autenticacion HMAC
- Manejo errores especificos
- Retry policy (429 Rate Limit)
- polly-advanced.md
- Combinar retry + circuit breaker
- Resilience pipeline v8
- Telemetria con Application Insights
- Fallback values
Checklists (2)
- api-integration-checklist.md
- HttpClientFactory configurado (evitar socket exhaustion)
- Timeout configurado (30s default)
- Retry policy para errores transitorios
- Circuit breaker para proteger sistema
- Autenticacion implementada (OAuth2/API Key)
- Secretos en Azure Key Vault (NO hardcoded)
- Logging request/response (sin datos sensibles)
- Tests unitarios con MockHttpMessageHandler
- Tests integracion con API real (ambiente test)
- Documentacion endpoints consumidos
- security-checklist.md
- Usar HTTPS obligatorio
- Validar certificados SSL (NO AllowInvalidCertificates)
- Tokens en IMemoryCache (NO static variables)
- Secretos en Key Vault
- Rate limiting implementado
- Input validation (sanitizar datos)
- Output encoding (evitar XSS)
- Audit logging (quien llamo que endpoint)
- CORS configurado (si aplica)
- OWASP API Security Top 10
Scripts (2)
- Test-ApiConnection.ps1
- Script PowerShell para test rapido conexion
- Obtener OAuth2 token
- Llamar endpoint test
- Validar respuesta
- Generate-ApiClient.ps1
- Generar cliente C# desde OpenAPI spec
- Usar NSwag o Kiota
- Configurar namespaces
- Generar modelos DTOs
Casos de Uso
Caso 1: Nueva integracion con el sistema externo
Usuario: "Necesito integrar con el sistema externo para matricular students"
Claude activa skill y proporciona:
1. Pattern: oauth2-client-credentials.md
2. Template: ExternalApiClient.cs.template
3. Example: external-api-example.md
4. Checklist: api-integration-checklist.md
Resultado: Cliente SistemaA funcional con OAuth2 y retry policy
Caso 2: Refactorizar HttpClient existente
Usuario: "Tengo un HttpClient estatico que causa problemas de sockets"
Claude activa skill y proporciona:
1. Pattern: httpclient-factory.md
2. Analiza codigo existente
3. Propone refactor a IHttpClientFactory
4. Actualiza Program.cs con DI
Resultado: HttpClient refactorizado con factory pattern
Caso 3: Añadir resiliencia a llamadas API
Usuario: "Las llamadas a el SaaS de RRHH del catalogo fallan a veces, necesito reintentos"
Claude activa skill y proporciona:
1. Pattern: retry-policy.md + circuit-breaker.md
2. Example: polly-advanced.md
3. Configuracion Polly v8
4. Telemetria con Application Insights
Resultado: Llamadas resilientes con retry + circuit breaker