Skip to content

LazyCats-dev/ao3-podfic-posting-helper / .agent/skills/angular-developer

angular-developer

Verified

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, services, or HTTP communication, or for best practices on reactivity (signals, linkedSignal, resource, httpResource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, naming conventions, or CLI tooling.

FileKindSize
SKILL.mdskill md10.5 KB
references/angular-animations.mdmarkdown3.9 KB
references/angular-aria.mdmarkdown18.2 KB
references/cli.mdmarkdown3.6 KB
references/component-harnesses.mdmarkdown2.7 KB
references/component-styling.mdmarkdown2.5 KB
references/components.mdmarkdown3.8 KB
references/creating-services.mdmarkdown3.2 KB
references/data-resolvers.mdmarkdown1.6 KB
references/define-routes.mdmarkdown2.1 KB
references/defining-providers.mdmarkdown2.2 KB
references/di-fundamentals.mdmarkdown3.4 KB
references/e2e-testing.mdmarkdown884 B
references/effects.mdmarkdown2.7 KB
references/environment-configuration.mdmarkdown3.3 KB
references/hierarchical-injectors.mdmarkdown2.1 KB
references/host-elements.mdmarkdown2.1 KB
references/http-client.mdmarkdown5.4 KB
references/injection-context.mdmarkdown1.9 KB
references/inputs.mdmarkdown2.4 KB
references/linked-signal.mdmarkdown2.6 KB
references/loading-strategies.mdmarkdown1.5 KB
references/mcp.mdmarkdown3.2 KB
references/migrations.mdmarkdown2.0 KB
references/naming-conventions.mdmarkdown5.4 KB
references/navigate-to-routes.mdmarkdown1.6 KB
references/outputs.mdmarkdown2.6 KB
references/pipes.mdmarkdown3.8 KB
references/reactive-forms.mdmarkdown3.5 KB
references/rendering-strategies.mdmarkdown1.8 KB
references/resource.mdmarkdown2.6 KB
references/route-animations.mdmarkdown1.6 KB
references/route-guards.mdmarkdown1.4 KB
references/router-lifecycle.mdmarkdown1.5 KB
references/router-testing.mdmarkdown3.7 KB
references/show-routes-with-outlets.mdmarkdown1.6 KB
references/signal-forms.mdmarkdown27.0 KB
references/signals-overview.mdmarkdown2.8 KB
references/tailwind-css.mdmarkdown1.8 KB
references/template-driven-forms.mdmarkdown3.7 KB
references/testing-fundamentals.mdmarkdown2.5 KB

references/http-client.md

View on GitHub
# HTTP communication with `HttpClient` and `httpResource`

Use Angular's HTTP APIs for backend communication so requests participate in dependency injection, interceptors, transfer cache, and security features.

## Setup

In Angular v21 and later, `HttpClient` is available for injection by default. Add `provideHttpClient(...)` only when an app needs to configure HTTP features for a specific injector:

```ts
import {provideHttpClient, withInterceptors} from '@angular/common/http';

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

- `HttpClient` uses the fetch backend by default.
- Use `withXhr()` only when upload progress events are required. Do not use `withXhr()` for server-side rendering.
- Use `provideHttpClient(...)` for feature configuration such as interceptors, XSRF options, XHR, or parent-request delegation.
- Calling `provideHttpClient()` with no features is not required for basic HTTP requests, but it configures the default HTTP feature set for that injector, including Angular's XSRF interceptor.
- Prefer `provideHttpClient(...)` over `HttpClientModule` for feature configuration, especially with multiple injectors.
- Use `withRequestsMadeViaParent()` when a child injector should add interceptors while still delegating to the parent HTTP chain.

## `HttpClient`

Encapsulate backend calls in injectable services, not components:

```ts
import {HttpClient} from '@angular/common/http';
import {Service, inject} from '@angular/core';

@Service()
export class UserService {
  private readonly http = inject(HttpClient);

  getUser(id: string) {
    return this.http.get<User>(`/api/users/${id}`);
  }
}
```

Important rules:

- `HttpClient` requests are cold `Observable`s. No request is sent until the `Observable` is subscribed to. Multiple subscriptions send multiple backend requests.
- Subscribe to mutation requests (`post`, `put`, `patch`, `delete`) so they execute.
- The generic type parameter is a type assertion only. Validate unknown backend data at runtime when the shape is not trusted.
- Use literal values for `responseType` and `observe`; if options are extracted, write values like `responseType: 'text' as const`.
- `HttpHeaders` and `HttpParams` are immutable; use the returned instance from `.set()` or `.append()`.
- Fetch options such as `timeout`, `cache`, `priority`, `mode`, `redirect`, `credentials`, `keepalive`, `referrer`, `referrerPolicy`, and `integrity` are supported where the backend supports them. `withCredentials: true` overrides `credentials`.
- Handle failures through `HttpErrorResponse`. Network and timeout failures use status `0`; backend failures use the server status code.
- Prefer the `async` pipe or `toSignal` for component reads so subscriptions are cleaned up.

## Interceptors

Prefer functional interceptors configured with `withInterceptors`.

```ts
import {
  HttpHandlerFn,
  HttpRequest,
  provideHttpClient,
  withInterceptors,
} from '@angular/common/http';

export function authInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn) {
  return next(req.clone({setHeaders: {Authorization: 'Bearer token'}}));
}

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

- Interceptors run in the order listed.
- Request and response objects are mostly immutable; clone before changing them.
- Request and response bodies are not deeply immutable. Avoid in-place body mutation because retries can run the same interceptor again.
- Use `inject()` inside functional interceptors for services.
- Use `HttpContextToken` for per-request metadata that interceptors need but the backend should not receive.
- Use DI-based interceptors only for existing code, and enable them with `withInterceptorsFromDi()`.

## Security

- `HttpClient` strips the XSSI prefix from JSON responses when present.
- `provideHttpClient()` configures XSRF protection by default for mutating relative and same-origin requests. It reads the `XSRF-TOKEN` cookie and sends the `X-XSRF-TOKEN` header.
- The backend must set the XSRF cookie and verify the header. Customize names with `withXsrfConfiguration(...)`; disable only deliberately with `withNoXsrfProtection()`.

## `httpResource`

Use `httpResource` to create an asynchronous derivation that fetches data over HTTP and exposes the result as reactive signals.

```ts
import {httpResource} from '@angular/common/http';
import {input} from '@angular/core';

export class UserProfile {
  readonly userId = input.required<string>();
  readonly user = httpResource(() => `/api/users/${this.userId()}`);
}
```

- `httpResource` is eager. It sends a request when its reactive request computation runs, not when an `Observable` is subscribed.
- When a dependency changes, it cancels the pending request and sends the next one.
- Return `undefined` from the request function to skip a backend request.
- Prefer `httpResource` for reads. Use `HttpClient` directly for mutations such as `POST`, `PUT`, `PATCH`, and `DELETE`.
- Guard `value()` reads with `hasValue()`; reading `value()` while the resource is in an error state throws.
- Use `httpResource.text`, `httpResource.blob`, or `httpResource.arrayBuffer` for non-JSON responses.
- Use the `parse` option to validate or transform responses with a runtime schema.
- Read `headers()`, `statusCode()`, and `progress()` when response metadata or download progress is needed. Set `reportProgress: true` for progress events.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall