HTTP Resource plugin for ng-openapi - Angular HTTP utilities with caching and state management
npm install @ng-openapi/http-resource
β‘Examples
β’
πDocumentation
β’
πIssues
The HTTP Resource plugin generates Angular services using the new experimental httpResource API instead of
traditional HttpClient. This provides automatic caching, state management, and reactive data loading for your OpenAPI
endpoints.
> β οΈ Experimental Feature: httpResource is still experimental in Angular. Use with caution in production.
``bash`
npm install @ng-openapi/http-resource ng-openapi --save-dev
`typescript
// openapi.config.ts
import { GeneratorConfig } from 'ng-openapi';
import { HttpResourcePlugin } from '@ng-openapi/http-resource';
export default {
input: './swagger.json',
output: './src/api',
clientName: 'NgOpenApi',
plugins: [HttpResourcePlugin],
} as GeneratorConfig;
`
`bash`
ng-openapi -c openapi.config.ts
`typescript
// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideDefaultClient } from './api/providers';
export const appConfig: ApplicationConfig = {
providers: [
provideNgOpenApiClient({
basePath: 'https://api.example.com'
})
]
};
`
`typescript
import { Component, inject } from '@angular/core';
import { UsersResource } from './api/resources';
@Component({
selector: 'app-users',
template:
Loading...
Error: {{ users.error() }}
})
export class UsersComponent {
private readonly usersResource = inject(UsersResource);
// Automatic caching and reactive updates
readonly users = this.usersResource.getUsers();
}
`Generated Structure
`
src/api/
βββ models/ # TypeScript interfaces
βββ resources/ # HTTP Resource services
β βββ index.ts # Resource exports
β βββ *.resource.ts # Generated resources
βββ services/ # Traditional HttpClient services
βββ providers.ts # Provider functions
βββ index.ts # Main exports
``- π Full Documentation
- π― Angular httpResource Guide
- π Live Examples