Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

angular-http

/angular-http

Opisuje HttpClient w Angularze z interceptorami, obsługą błędów, ponawianiem i cache'owaniem, w tym funkcyjne interceptory i typowane odpowiedzi.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

95/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść30 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Opisuje HttpClient w Angularze z interceptorami, obsługą błędów, ponawianiem i cache'owaniem, w tym funkcyjne interceptory i typowane odpowiedzi.

Wyzwalacze z opisu

HttpClientAngular HTTPinterceptorsAPI callsAngular RESTHTTP error handlingauth interceptor
Oryginalny opis (EN)

Angular HttpClient with interceptors, error handling, retry, and caching patterns. Covers functional interceptors and typed responses. USE WHEN: user mentions "HttpClient", "Angular HTTP", "interceptors", "API calls", "Angular REST", "HTTP error handling", "auth interceptor" DO NOT USE FOR: Axios - use `axios` skill, Fetch API directly, backend HTTP frameworks

Jak działa

  1. HttpClient Setup
  2. Functional Interceptors (Angular 15+)
  3. Service Pattern with Error Handling
  4. Typed Responses
  5. Anti-Patterns
  6. Quick Troubleshooting
Sekcje z nagłówków SKILL.md, w oryginale · 124 linii, 426 słów
Podgląd SKILL.md
---
name: angular-http
description: |
  Angular HttpClient with interceptors, error handling, retry, and caching patterns.
  Covers functional interceptors and typed responses.

  USE WHEN: user mentions "HttpClient", "Angular HTTP", "interceptors", "API calls",
  "Angular REST", "HTTP error handling", "auth interceptor"

  DO NOT USE FOR: Axios - use `axios` skill, Fetch API directly,
  backend HTTP frameworks
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Angular HTTP - Quick Reference

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `angular`, topic: `http` for comprehensive documentation.

## HttpClient Setup

```typescript
// app.config.ts
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { authInterceptor } from './core/interceptors/auth.interceptor';
import { errorInterceptor } from './core/interceptors/error.interceptor';

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withInterceptors([authInterceptor, errorInterceptor])),
  ]
};
```

## Functional Interceptors (Angular 15+)

```typescript
// Auth interceptor
import { HttpInterceptorFn } from '@angular/common/http';
import { inject } from '@angular/core';

export const authInterceptor: HttpInterceptorFn = (req, next) => {
  const token = inject(AuthService).getToken();
  if (token) {
    req = req.clone({
      setHeaders: { Authorization: `Bearer ${token}` },
    });
  }
  return next(req);
};

// Error interceptor
export const errorInterceptor: HttpInterceptorFn = (req, next) => {
  return next(req).pipe(
    catchError((error: HttpErrorResponse) => {
      if (error.status === 401) {
        inject(Router).navigate(['/login']);
      }
      return throwError(() => error);
    })
  );
};

// Loading interceptor
export const loadingInterceptor: HttpInterceptorFn = (req, next) => {
  const loading = inject(LoadingService);
  loading.show();
  return next(req).pipe(finalize(() => loading.hide()));
};
```

## Service Pattern with Error Handling

```typescript
@Injectable({ providedIn: 'root' })
export class UserService {
  private http = inject(HttpClient);
  private baseUrl = '/api/users';

  getUsers(): Observable<User[]> {
    return this.http.get<User[]>(this.baseUrl).pipe(
      retry({ count: 2, delay: 1000 }),
      catchError(this.handleError),
    );
  }

  create(user: CreateUserDto): Observable<User> {
    return this.http.post<User>(this.baseUrl, user).pipe(
      catchError(this.handleError),
    );
  }

  private handleError(error: HttpErrorResponse): Observable<never> {
    let message = 'An error occurred';
    if (error.status === 0) {
      message = 'Network error';
    } else if (error.status === 404) {
      message = 'Resource not found';
    }
    return throwError(() => new Error(message));
  }
}
```

## Typed Responses

```typescript
// With observe: 'response' for full response
getWithHeaders(): Observable<HttpResponse<User[]>> {
  return this.http.get<User[]>(this.baseUrl, { observe: 'response' });
}

// With params
search(query: string, page: number): Observable<PaginatedResult<User>> {
  const params = new HttpParams()
    .set('q', query)
    .set('page', page.toString());
  return this.http.get<PaginatedResult<User>>(this.baseUrl, { params });
}
```

## Anti-Patterns

| Anti-Pattern | Why It's Bad | Correct Approach |
|--------------|--------------|------------------|
| Class-based interceptors | Verbose, deprecated | Use functional `HttpInterceptorFn` |
| Not typing responses | No compile-time checks | Use `http.get<Type>()` |
| Subscribing in services | Tight coupling | Return observables, subscribe in components |
| No error handling | Silent failures | Use `catchError` in service |

## Quick Troubleshooting

| Issue | Likely Cause | Solution |
|-------|--------------|----------|
| HTTP call not firing | Forgot to subscribe | Subscribe to the observable |
| Interceptor not running | Not in providers | Add to `withInterceptors()` |
| CORS error | Backend config | Configure CORS on server |
| Wrong content type | Missing header | HttpClient sets JSON by default |

Wersje

W bazie nie ma innych skilli o nazwie angular-http.

Migawka bazy z 28.10.2026 · wersja paczki 3109e101391c (skrót SHA-256 całej paczki)

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100angular-http-client
    Integruje HttpClient, interceptory i interakcje z API w Angularze.
  • 100http-clients
    Opisuje klienty HTTP dla frontendu i Node.js: Axios, Fetch API, ky i ofetch, z interceptorami, obsługą błędów, ponawianiem i zarządzaniem tokenami uwierzytelniającymi.
  • 80Angular HttpClient Migration v6
    Migruje z HttpModule i Http na HttpClientModule i HttpClient w epoce Angulara 5 do 6, gdy stare API blokuje rozwój.
  • 95auth0-angular
    Dodaje logowanie do aplikacji Angular przez SDK Auth0 ze strażnikami tras i interceptorami HTTP.
  • 100axios
    Obsługuje Axios, klienta HTTP opartego na obietnicach dla przeglądarki i Node.js: żądania HTTP, interceptory, instancje, nagłówki autoryzacji i obsługa błędów.
  • 90angular-patterns
    Podpowiada wzorce Angular: wstrzykiwanie zależności, interceptory HTTP, strażników tras, RxJS, Signal Store i wybór między Observable a sygnałem.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.