Communityコーディング&開発github.com

analogjs/angular-http

Angular v20+ における HTTP データフェッチを、resource()、httpResource()、HttpClient を使用して実装します。API 呼び出し、シグナルによるデータ読み込み、リクエスト/レスポンス処理、インターセプターに使用します。データフェッチ、API 統合、ローディング状態、エラーハンドリング、または Observable ベースの HTTP からシグナルベースのパターンへの変換をトリガーとします。

angular-http とは?

analogjs/angular-http スキルは、Angular v20 以降のアプリケーションで最新のシグナルベースの HTTP データフェッチパターンを実装するための包括的なガイドです。主に `resource()` 関数、`httpResource()`、そして従来の `HttpClient` を使用した API 呼び出し、データの読み込み、リクエスト/レスポンス処理、インターセプターの設定をカバーします。このスキルは、Observable ベースの HTTP 処理からシグナルベースのリアクティブパターンへの移行を促進し、ローディング状態やエラーハンドリングを効率的に管理する方法を提供します。Claude Code、Coder、Cursor、Copilot などの AI エージェント環境での使用を想定しており、開発者が新しい Angular のリアクティブ機能を活用して、より宣言的で効率的なデータフェッチロジックを記述できるよう支援します。ドキュメントには具体的なコード例、ベストプラクティス、そして一般的なユースケースが含まれています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/analogjs/angular-skills/tree/main/skills/angular-http

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

angular-http は何をしますか?

Angular v20+ において、resource()、httpResource()、HttpClient を使用して HTTP データフェッチを実装します。API 呼び出し、シグナルによるデータ読み込み、リクエスト/レスポンス処理、インターセプターに使用します。データフェッチ、API 統合、ローディング状態、エラーハンドリング、または Observable ベースの HTTP からシグナルベースのパターンへの変換をトリガーとします。

概要

このスキルは、Angular アプリケーションで HTTP データを取得するための最新のアプローチを提供します。Angular v20 で導入された resource() と httpResource() を活用し、コンポーネント内で宣言的かつリアクティブにデータを管理します。

主な機能

  • resource(): 汎用的な非同期データリソース管理
  • httpResource(): HttpClient と統合された特化型リソース
  • HttpClient: 従来の HTTP クライアント(後方互換性のため)
  • シグナルベースのローディング状態管理
  • エラーハンドリング
  • インターセプターの設定

使用方法

httpResource() の基本的な使用

import { httpResource } from '@angular/common/http';

const todos = httpResource<Todo[]>('https://api.example.com/todos');

動的なリクエスト

const userId = signal(1);
const user = httpResource<User>(() => `https://api.example.com/users/${userId()}`);

エラーハンドリング

const data = httpResource<Data>('/api/data', {
  mapError: (error: HttpErrorResponse) => {
    console.error('API エラー:', error);
    return { message: 'データの取得に失敗しました', status: error.status };
  }
});

インターセプター

インターセプターは従来の HttpClient と同様に設定します:

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { AuthInterceptor } from './auth.interceptor';

providers: [
  { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
]

ベストプラクティス

  • コンポーネント内で直接データフェッチを記述する: resource() と httpResource() はコンポーネント内で直接使用するよう設計されています。
  • ローディング状態を明示的に扱う: シグナルを使用してローディング中、エラー、成功の各状態を管理します。
  • 不要な再フェッチを避ける: 依存関係が変更された場合のみリクエストが再実行されるよう、適切にシグナルを設定します。

トリガーとなるシナリオ

  • ユーザーがデータ一覧を表示する必要がある場合
  • API エンドポイントからデータを取得する際
  • ローディング状態やエラー状態を UI に反映する必要がある場合
  • Observable ベースの既存コードをシグナルベースに移行する場合

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

analogjs/angular-component

Create modern Angular standalone components following v20+ best practices. Use for building UI components with signal-based inputs/outputs, OnPush change detection, host bindings, content projection, and lifecycle hooks. Triggers on component creation, refactoring class-based inputs to signals, adding host bindings, or implementing accessible interactive components.

analogjs/angular-di

Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration. Use for service architecture, providing dependencies at different levels, creating injectable tokens, and managing singleton vs scoped services. Triggers on service creation, configuring providers, using injection tokens, or understanding DI hierarchy.

analogjs/angular-directives

Create custom directives in Angular v20+ for DOM manipulation and behavior extension. Use for attribute directives that modify element behavior/appearance, structural directives for portals/overlays, and host directives for composition. Triggers on creating reusable DOM behaviors, extending element functionality, or composing behaviors across components. Note - use native @if/@for/@switch for control flow, not custom structural directives.

analogjs/angular-forms

Build signal-based forms in Angular v21+ using the new Signal Forms API. Use for form creation with automatic two-way binding, schema-based validation, field state management, and dynamic forms. Triggers on form implementation, adding validation, creating multi-step forms, or building forms with conditional fields. Signal Forms are experimental but recommended for new Angular projects. Don't use for template-driven forms without signals or third-party form libraries like Formly or ngx-formly.

analogjs/angular-routing

Implement routing in Angular v20+ applications with lazy loading, functional guards, resolvers, and route parameters. Use for navigation setup, protected routes, route-based data loading, and nested routing. Triggers on route configuration, adding authentication guards, implementing lazy loading, or reading route parameters with signals.

analogjs/angular-signals

Implement signal-based reactive state management in Angular v20+. Use for creating reactive state with signal(), derived state with computed(), dependent state with linkedSignal(), and side effects with effect(). Triggers on state management questions, converting from BehaviorSubject/Observable patterns to signals, or implementing reactive data flows.

analogjs/angular-ssr

Implement server-side rendering and hydration in Angular v20+ using @angular/ssr. Use for SSR setup, hydration strategies, prerendering static pages, and handling browser-only APIs. Triggers on SSR configuration, fixing hydration mismatches, prerendering routes, or making code SSR-compatible.

analogjs/angular-testing

Write unit and integration tests for Angular v20+ applications using Vitest or Jasmine with TestBed and modern testing patterns. Use for testing components with signals, OnPush change detection, services with inject(), and HTTP interactions. Triggers on test creation, testing signal-based components, mocking dependencies, or setting up test infrastructure. Don't use for E2E testing with Cypress or Playwright, or for testing non-Angular JavaScript/TypeScript code.

analogjs/angular-tooling

Use Angular CLI and development tools effectively in Angular v20+ projects. Use for project setup, code generation, building, testing, and configuration. Triggers on creating new projects, generating components/services/modules, configuring builds, running tests, or optimizing production builds. Don't use for Nx workspace commands, custom Webpack configurations, or non-Angular CLI build systems like Vite standalone or esbuild direct usage.

関連スキル