@angular/common plugin generates type-safe HTTP client code for Angular applications, supporting both the traditional HttpRequest pattern and the new httpResource API introduced in Angular 18.
Installation
Install the required dependencies:Configuration
Add the@angular/common plugin to your OpenAPI TypeScript configuration:
openapi-ts.config.ts
The
@angular/common plugin requires @hey-api/client-angular and @hey-api/sdk plugins as dependencies.Features
HTTP Requests
Generates functions that returnHttpRequest<T> instances, compatible with Angular’s HTTP client:
HTTP Resources
Generates resource APIs using Angular 18’s newhttpResource for reactive data fetching:
httpResource requires Angular 18+ and provides automatic reactivity, caching, and loading states.Configuration Options
The@angular/common plugin accepts the following options:
Generate HTTP Request functions. Set to
false to disable, or use a strategy:'flat'- Individual functions'byTags'- Group by OpenAPI tags into classes'single'- All operations in one classtrue- Equivalent to'flat'- Object with detailed configuration
Generate HTTP Resource methods. Same strategy options as
httpRequests.Export generated code from the main index file.
Include JSDoc comments from OpenAPI descriptions.
Advanced HTTP Requests Configuration
How to group operations:
'flat'- Standalone functions'byTags'- One class per OpenAPI tag'single'- All operations in one class
Container type for grouped operations. Currently only
'class' is supported.Customize class names. Use
{{name}} as a placeholder for tag names.Examples:'{{name}}Service'- Appends “Service” to tag name{ name: '{{name}}Api', case: 'PascalCase' }- With custom casing
Customize method/function names.Examples:
{ case: 'camelCase' }- Force camelCase'{{name}}Request'- Append suffix to method names
How to derive nesting structure:
'operationId'- Split operationId by delimiters (e.g.,users.list→Users.list())'id'- Use operation ID as-is, no nesting
Regular expression for splitting operationId when
nesting is 'operationId'.How methods are attached to classes. Currently only
'instance' is supported (requires new ClassName()).Container name for operations without tags when using
strategy: 'byTags'.Advanced HTTP Resources Configuration
Accepts the same configuration options as HTTP Requests:Usage Patterns
Flat Strategy (Standalone Functions)
openapi-ts.config.ts
By Tags Strategy (Service Classes)
openapi-ts.config.ts
Single Strategy (One Service Class)
openapi-ts.config.ts
Examples
Complete Component Example
app.component.ts
Using HTTP Requests with HttpClient
pet.service.ts
Generated Code Structure
The plugin generates code in the@angular subdirectory:
Example Generated Code
Dependencies
The@angular/common plugin automatically declares these dependencies:
@hey-api/client-angular- Angular HTTP client adapter@hey-api/sdk- Core SDK functionality
Migration Guide
From HttpClient Direct Usage
Before:To HTTP Resources
Before (using HttpClient):Best Practices
Use HTTP Resources for reactive data
Leverage Angular 18’s
httpResource for components that display server data. It provides automatic loading states and error handling.Use HTTP Requests for imperative operations
Use
HttpRequest functions for actions triggered by user interactions (create, update, delete operations).Organize by tags
Use
strategy: 'byTags' to generate service classes that align with your API structure and improve code organization.For Angular versions before 18, use
httpRequests: true and httpResources: false to generate only HTTP Request functions.