home / skills / hoangnguyen0403 / agent-skills-standard / http-client
This skill helps you implement HTTP client best practices with functional interceptors, typed responses, and service-based calls to improve reliability.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill http-clientReview the files below or copy the command above to add this skill to your agents.
---
name: HTTP Client
description: Best practices for HttpClient, Interceptors, and API interactions.
metadata:
labels: [angular, http, api, interceptors]
triggers:
files: ['**/*.service.ts', '**/*.interceptor.ts']
keywords: [HttpClient, HttpInterceptorFn, withInterceptors]
---
# HTTP Client
## **Priority: P1 (HIGH)**
## Principles
- **Functional Interceptors**: Use `HttpInterceptorFn`. Class-based interceptors are deprecated.
- **Typed Responses**: Always type `http.get<User[]>()`.
- **Services**: Encapsulate all HTTP calls in Services. Never call `http` in Components.
## Guidelines
- **Caching**: Implement caching in interceptors or using `shareReplay(1)` in services.
- **Error Handling**: Catch errors in services or global interceptors, not components.
- **Context**: Use `HttpContext` to pass metadata to interceptors (e.g., specific caching rules).
## References
- [Interceptors](references/interceptors.md)
This skill documents practical best practices for using HTTP clients, with emphasis on functional interceptors, typed responses, and service-based API access. It focuses on patterns that improve safety, testability, and maintainability across TypeScript and multiple platform ecosystems. The guidance targets real-world concerns like caching, error handling, and passing metadata to interceptors.
It prescribes using functional interceptors (HttpInterceptorFn) to centralize cross-cutting HTTP behavior and avoid deprecated class-based interceptors. All HTTP calls are encapsulated inside dedicated services that return strongly typed responses. Caching, error transformation, and metadata-driven behavior are implemented in interceptors or service layers so components remain logic-free.
Why prefer functional interceptors over class-based ones?
Functional interceptors are the modern pattern: they are simpler, easier to compose and test, and replace deprecated class-based interceptors.
Where should I catch and transform HTTP errors?
Catch and transform errors in services or a global interceptor to keep components free of HTTP-specific logic and to provide consistent error shapes.