Skip to main content
The @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 return HttpRequest<T> instances, compatible with Angular’s HTTP client:

HTTP Resources

Generates resource APIs using Angular 18’s new httpResource 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:
boolean | 'flat' | 'byTags' | 'single' | object
default:"'flat'"
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 class
  • true - Equivalent to 'flat'
  • Object with detailed configuration
boolean | 'flat' | 'byTags' | 'single' | object
default:"'flat'"
Generate HTTP Resource methods. Same strategy options as httpRequests.
boolean
default:false
Export generated code from the main index file.
boolean
default:true
Include JSDoc comments from OpenAPI descriptions.

Advanced HTTP Requests Configuration

'flat' | 'byTags' | 'single'
default:"'flat'"
How to group operations:
  • 'flat' - Standalone functions
  • 'byTags' - One class per OpenAPI tag
  • 'single' - All operations in one class
'class'
default:"'class'"
Container type for grouped operations. Currently only 'class' is supported.
string | object
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
string | object
Customize method/function names.Examples:
  • { case: 'camelCase' } - Force camelCase
  • '{{name}}Request' - Append suffix to method names
'operationId' | 'id' | function
default:"'operationId'"
How to derive nesting structure:
  • 'operationId' - Split operationId by delimiters (e.g., users.list → Users.list())
  • 'id' - Use operation ID as-is, no nesting
RegExp
default:"/[.\\u002F]/"
Regular expression for splitting operationId when nesting is 'operationId'.
'instance'
default:"'instance'"
How methods are attached to classes. Currently only 'instance' is supported (requires new ClassName()).
string
default:"'default'"
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
Generates individual functions:

By Tags Strategy (Service Classes)

openapi-ts.config.ts
Generates classes grouped by OpenAPI tags:

Single Strategy (One Service Class)

openapi-ts.config.ts
Generates one class containing all operations:

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
These must be included in your plugin configuration:

Migration Guide

From HttpClient Direct Usage

Before:
After:

To HTTP Resources

Before (using HttpClient):
After (using httpResource):

Best Practices

1

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.
2

Use HTTP Requests for imperative operations

Use HttpRequest functions for actions triggered by user interactions (create, update, delete operations).
3

Organize by tags

Use strategy: 'byTags' to generate service classes that align with your API structure and improve code organization.
4

Leverage dependency injection

Generated resource classes are decorated with @Injectable({ providedIn: 'root' }), allowing direct injection into components.
For Angular versions before 18, use httpRequests: true and httpResources: false to generate only HTTP Request functions.