tangled
alpha
login
or
join now
mokkenstorm.dev
/
openapi-ts
0
fork
atom
fork of hey-api/openapi-ts because I need some additional things
0
fork
atom
overview
issues
pulls
pipelines
docs: add Angular client documentation
Max Scopp
7 months ago
6ab6bb57
2f84f752
+135
-5
2 changed files
expand all
collapse all
unified
split
docs
.vitepress
config
en.ts
openapi-ts
clients
angular.md
+1
-1
docs/.vitepress/config/en.ts
···
108
108
},
109
109
{
110
110
link: '/openapi-ts/clients/angular',
111
111
-
text: 'Angular <span data-soon>soon</span>',
111
111
+
text: 'Angular',
112
112
},
113
113
{
114
114
link: '/openapi-ts/clients/effect',
+134
-4
docs/openapi-ts/clients/angular.md
···
3
3
description: Angular client for Hey API. Compatible with all our features.
4
4
---
5
5
6
6
-
# Angular <span data-soon>soon</span>
6
6
+
<script setup lang="ts">
7
7
+
import { embedProject } from '../../embed'
8
8
+
</script>
7
9
8
8
-
<FeatureStatus issueNumber=1072 name="Angular" />
10
10
+
<Heading>
11
11
+
<h1>Angular</h1>
12
12
+
<VersionLabel value="v1" />
13
13
+
<ExperimentalLabel />
14
14
+
</Heading>
9
15
10
16
### About
11
17
12
12
-
[Angular](https://angular.dev/) is a web framework that empowers developers to build fast, reliable applications.
18
18
+
[Angular](https://angular.dev/) is a web framework for building fast, reliable applications.
19
19
+
20
20
+
::: warning Requirements
21
21
+
**Angular 19+** is required for full feature support, including the experimental `httpResource` API.
22
22
+
:::
23
23
+
24
24
+
::: tip First Release
25
25
+
Angular client support is in its first release. Share your feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues).
26
26
+
:::
27
27
+
28
28
+
## Features
29
29
+
30
30
+
- Modern Angular patterns with signals and reactive programming
31
31
+
- Dependency injection with `@Injectable()` decorators
32
32
+
- Type-safe response data and errors
33
33
+
- Experimental **httpResource** support (Angular 19+)
34
34
+
35
35
+
## Usage
36
36
+
37
37
+
Add `@hey-api/client-angular` to your plugins:
38
38
+
39
39
+
```js
40
40
+
export default {
41
41
+
input: 'https://get.heyapi.dev/hey-api/backend',
42
42
+
output: 'src/client',
43
43
+
plugins: [
44
44
+
'@hey-api/client-angular', // [!code ++]
45
45
+
],
46
46
+
};
47
47
+
```
48
48
+
49
49
+
After generating the client, integrate it with Angular's `HttpClient` by adding `provideHeyApiClient` to your app configuration:
50
50
+
51
51
+
```ts
52
52
+
import { provideHttpClient, withFetch } from '@angular/common/http';
53
53
+
import { provideHeyApiClient, client } from './client/client.gen';
13
54
14
14
-
<!--@include: ../../partials/sponsors.md-->
55
55
+
export const appConfig = {
56
56
+
providers: [
57
57
+
provideHttpClient(withFetch()),
58
58
+
provideHeyApiClient(client), // [!code ++]
59
59
+
],
60
60
+
};
61
61
+
```
62
62
+
63
63
+
## Configuration
64
64
+
65
65
+
### Injectable Classes Configuration
66
66
+
67
67
+
You can configure the Angular client to generate injectable classes by setting the `asClass` option to `true` in your plugin configuration. This will generate Angular services with `@Injectable()` decorators, making them available for dependency injection.
68
68
+
69
69
+
```js
70
70
+
export default {
71
71
+
input: 'https://get.heyapi.dev/hey-api/backend',
72
72
+
output: 'src/client',
73
73
+
plugins: [
74
74
+
{
75
75
+
name: '@hey-api/client-angular',
76
76
+
asClass: true, // [!code ++]
77
77
+
},
78
78
+
],
79
79
+
};
80
80
+
```
81
81
+
82
82
+
::: warning
83
83
+
While this feature is available, it is **discouraged** as it can negatively impact tree shaking, leading to larger bundle sizes. Consider using other configuration options for better optimization.
84
84
+
:::
85
85
+
86
86
+
### Angular Providers
87
87
+
88
88
+
Use `provideHeyApiClient` to integrate the generated client with Angular's `HttpClient`:
89
89
+
90
90
+
```ts
91
91
+
import { provideHttpClient, withFetch } from '@angular/common/http';
92
92
+
import { provideHeyApiClient, client } from './client/client.gen';
93
93
+
94
94
+
export const appConfig = {
95
95
+
providers: [provideHttpClient(withFetch()), provideHeyApiClient(client)],
96
96
+
};
97
97
+
```
98
98
+
99
99
+
### `createClient()`
100
100
+
101
101
+
Manually create a client instance for custom configurations:
102
102
+
103
103
+
```ts
104
104
+
import { createClient } from './client/client';
105
105
+
106
106
+
const myClient = createClient({
107
107
+
baseUrl: 'https://example.com',
108
108
+
});
109
109
+
```
110
110
+
111
111
+
## Plugin Configuration
112
112
+
113
113
+
The `@hey-api/client-angular` plugin supports options like `throwOnError` for error handling:
114
114
+
115
115
+
```js
116
116
+
export default {
117
117
+
input: 'https://get.heyapi.dev/hey-api/backend',
118
118
+
output: 'src/client',
119
119
+
plugins: [
120
120
+
{
121
121
+
name: '@hey-api/client-angular',
122
122
+
throwOnError: false,
123
123
+
},
124
124
+
],
125
125
+
};
126
126
+
```
127
127
+
128
128
+
## httpResource
129
129
+
130
130
+
Angular 19 introduces a experimental api – `httpResource`, a reactive approach to data loading. Enable it with:
131
131
+
132
132
+
```js
133
133
+
export default {
134
134
+
plugins: [
135
135
+
{
136
136
+
name: '@angular/common',
137
137
+
httpResource: {
138
138
+
enabled: true,
139
139
+
asClass: true,
140
140
+
},
141
141
+
},
142
142
+
],
143
143
+
};
144
144
+
```