Quick Start
This guide will walk you through creating your first API integration with ngrx-rtk-query, from defining endpoints to using them in your components.Overview
We’ll build a simple posts management feature that demonstrates:- Creating an API with queries and mutations
- Configuring the store provider
- Using queries in components
- Triggering mutations
- Working with signal inputs
Step-by-Step Guide
Create Your API Definition
Use
createApi to define your API endpoints. This will auto-generate typed hooks:api.ts
The
tagTypes and cache tags (providesTags/invalidatesTags) enable automatic cache invalidation when data changes.Use Queries in a Component
Create a list component that fetches and displays posts:
posts-list.component.ts
The query hook returns a signal with properties like
isLoading(), isError(), data(), etc. You can access them as postsQuery.isLoading() for fine-grained change detection.Key Concepts
Auto-Generated Hooks
When you export hooks from your API, they’re fully typed and ready to use:Signal Access Patterns
You can access query/mutation state in two ways:Cache Invalidation
Use tags to automatically invalidate and refetch data:providesTags: Tags that this endpoint providesinvalidatesTags: Tags to invalidate when mutation succeeds
Mutation Unwrapping
Use.unwrap() to handle success/error:
What’s Next?
Now that you’ve built your first API integration, explore more advanced features:Queries
Learn about lazy queries, skip tokens, and query options
Mutations
Master mutations, optimistic updates, and error handling
Infinite Queries
Implement pagination and infinite scrolling
Code Splitting
Learn how to lazy-load API definitions
You can follow the official RTK Query guide with slight variations for Angular-specific patterns.