Skip to content

Commit 461b1e8

Browse files
committed
docs: add examples and docs for SSE support
1 parent d7e660e commit 461b1e8

37 files changed

+3376
-25
lines changed

docs/openapi-ts/clients/angular.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,68 @@ This section is under construction. We appreciate your patience.
204204
This section is under construction. We appreciate your patience.
205205
:::
206206

207+
## Server-Sent Events
208+
209+
When your OpenAPI spec defines endpoints with `text/event-stream` responses, the SDK generates SSE-enabled functions that return an async stream instead of a regular response.
210+
211+
### Consuming a stream
212+
213+
```js
214+
import { watchStockPrices } from './client/sdk.gen';
215+
216+
const { stream } = await watchStockPrices();
217+
218+
for await (const event of stream) {
219+
console.log(event);
220+
}
221+
```
222+
223+
### Callbacks
224+
225+
You can use `onSseEvent` and `onSseError` callbacks for additional event and error processing.
226+
227+
```js
228+
const { stream } = await watchStockPrices({
229+
onSseEvent: (event) => {
230+
// access event.data, event.event, event.id, event.retry
231+
},
232+
onSseError: (error) => {
233+
console.error('SSE error:', error);
234+
},
235+
});
236+
```
237+
238+
### Cancellation
239+
240+
Use an `AbortController` to cancel the stream.
241+
242+
```js
243+
const controller = new AbortController();
244+
245+
const { stream } = await watchStockPrices({
246+
signal: controller.signal,
247+
});
248+
249+
// cancel the stream
250+
controller.abort();
251+
```
252+
253+
### Retry
254+
255+
SSE connections automatically reconnect on failure with exponential backoff. You can configure the retry behavior.
256+
257+
```js
258+
const { stream } = await watchStockPrices({
259+
sseDefaultRetryDelay: 3000, // initial retry delay (default: 3000ms)
260+
sseMaxRetryAttempts: 5, // max retry attempts
261+
sseMaxRetryDelay: 30000, // max retry delay cap (default: 30000ms)
262+
});
263+
```
264+
265+
::: warning
266+
Angular `HttpClient` interceptors do not apply to SSE connections. The SSE client uses the native Fetch API under the hood.
267+
:::
268+
207269
## Build URL
208270

209271
If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

docs/openapi-ts/clients/angular/v19.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,68 @@ This section is under construction. We appreciate your patience.
204204
This section is under construction. We appreciate your patience.
205205
:::
206206

207+
## Server-Sent Events
208+
209+
When your OpenAPI spec defines endpoints with `text/event-stream` responses, the SDK generates SSE-enabled functions that return an async stream instead of a regular response.
210+
211+
### Consuming a stream
212+
213+
```js
214+
import { watchStockPrices } from './client/sdk.gen';
215+
216+
const { stream } = await watchStockPrices();
217+
218+
for await (const event of stream) {
219+
console.log(event);
220+
}
221+
```
222+
223+
### Callbacks
224+
225+
You can use `onSseEvent` and `onSseError` callbacks for additional event and error processing.
226+
227+
```js
228+
const { stream } = await watchStockPrices({
229+
onSseEvent: (event) => {
230+
// access event.data, event.event, event.id, event.retry
231+
},
232+
onSseError: (error) => {
233+
console.error('SSE error:', error);
234+
},
235+
});
236+
```
237+
238+
### Cancellation
239+
240+
Use an `AbortController` to cancel the stream.
241+
242+
```js
243+
const controller = new AbortController();
244+
245+
const { stream } = await watchStockPrices({
246+
signal: controller.signal,
247+
});
248+
249+
// cancel the stream
250+
controller.abort();
251+
```
252+
253+
### Retry
254+
255+
SSE connections automatically reconnect on failure with exponential backoff. You can configure the retry behavior.
256+
257+
```js
258+
const { stream } = await watchStockPrices({
259+
sseDefaultRetryDelay: 3000, // initial retry delay (default: 3000ms)
260+
sseMaxRetryAttempts: 5, // max retry attempts
261+
sseMaxRetryDelay: 30000, // max retry delay cap (default: 30000ms)
262+
});
263+
```
264+
265+
::: warning
266+
Angular `HttpClient` interceptors do not apply to SSE connections. The SSE client uses the native Fetch API under the hood.
267+
:::
268+
207269
## Build URL
208270

209271
If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

docs/openapi-ts/clients/axios.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,68 @@ client.instance.interceptors.request.use((config) => {
184184
});
185185
```
186186

187+
## Server-Sent Events
188+
189+
When your OpenAPI spec defines endpoints with `text/event-stream` responses, the SDK generates SSE-enabled functions that return an async stream instead of a regular response.
190+
191+
### Consuming a stream
192+
193+
```js
194+
import { watchStockPrices } from './client/sdk.gen';
195+
196+
const { stream } = await watchStockPrices();
197+
198+
for await (const event of stream) {
199+
console.log(event);
200+
}
201+
```
202+
203+
### Callbacks
204+
205+
You can use `onSseEvent` and `onSseError` callbacks for additional event and error processing.
206+
207+
```js
208+
const { stream } = await watchStockPrices({
209+
onSseEvent: (event) => {
210+
// access event.data, event.event, event.id, event.retry
211+
},
212+
onSseError: (error) => {
213+
console.error('SSE error:', error);
214+
},
215+
});
216+
```
217+
218+
### Cancellation
219+
220+
Use an `AbortController` to cancel the stream.
221+
222+
```js
223+
const controller = new AbortController();
224+
225+
const { stream } = await watchStockPrices({
226+
signal: controller.signal,
227+
});
228+
229+
// cancel the stream
230+
controller.abort();
231+
```
232+
233+
### Retry
234+
235+
SSE connections automatically reconnect on failure with exponential backoff. You can configure the retry behavior.
236+
237+
```js
238+
const { stream } = await watchStockPrices({
239+
sseDefaultRetryDelay: 3000, // initial retry delay (default: 3000ms)
240+
sseMaxRetryAttempts: 5, // max retry attempts
241+
sseMaxRetryDelay: 30000, // max retry delay cap (default: 30000ms)
242+
});
243+
```
244+
245+
::: warning
246+
Axios interceptors registered through `client.instance.interceptors` do not apply to SSE connections. The SSE client uses the native Fetch API under the hood.
247+
:::
248+
187249
## Build URL
188250

189251
If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

docs/openapi-ts/clients/fetch.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,68 @@ client.interceptors.request.use((request, options) => {
262262
});
263263
```
264264

265+
## Server-Sent Events
266+
267+
When your OpenAPI spec defines endpoints with `text/event-stream` responses, the SDK generates SSE-enabled functions that return an async stream instead of a regular response.
268+
269+
### Consuming a stream
270+
271+
```js
272+
import { watchStockPrices } from './client/sdk.gen';
273+
274+
const { stream } = await watchStockPrices();
275+
276+
for await (const event of stream) {
277+
console.log(event);
278+
}
279+
```
280+
281+
### Callbacks
282+
283+
You can use `onSseEvent` and `onSseError` callbacks for additional event and error processing.
284+
285+
```js
286+
const { stream } = await watchStockPrices({
287+
onSseEvent: (event) => {
288+
// access event.data, event.event, event.id, event.retry
289+
},
290+
onSseError: (error) => {
291+
console.error('SSE error:', error);
292+
},
293+
});
294+
```
295+
296+
### Cancellation
297+
298+
Use an `AbortController` to cancel the stream.
299+
300+
```js
301+
const controller = new AbortController();
302+
303+
const { stream } = await watchStockPrices({
304+
signal: controller.signal,
305+
});
306+
307+
// cancel the stream
308+
controller.abort();
309+
```
310+
311+
### Retry
312+
313+
SSE connections automatically reconnect on failure with exponential backoff. You can configure the retry behavior.
314+
315+
```js
316+
const { stream } = await watchStockPrices({
317+
sseDefaultRetryDelay: 3000, // initial retry delay (default: 3000ms)
318+
sseMaxRetryAttempts: 5, // max retry attempts
319+
sseMaxRetryDelay: 30000, // max retry delay cap (default: 30000ms)
320+
});
321+
```
322+
323+
::: tip
324+
Request interceptors registered through `client.interceptors.request` apply to SSE connections, including on each reconnect attempt.
325+
:::
326+
265327
## Build URL
266328

267329
If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

docs/openapi-ts/clients/ky.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,68 @@ client.interceptors.request.use((request, options) => {
260260
});
261261
```
262262

263+
## Server-Sent Events
264+
265+
When your OpenAPI spec defines endpoints with `text/event-stream` responses, the SDK generates SSE-enabled functions that return an async stream instead of a regular response.
266+
267+
### Consuming a stream
268+
269+
```js
270+
import { watchStockPrices } from './client/sdk.gen';
271+
272+
const { stream } = await watchStockPrices();
273+
274+
for await (const event of stream) {
275+
console.log(event);
276+
}
277+
```
278+
279+
### Callbacks
280+
281+
You can use `onSseEvent` and `onSseError` callbacks for additional event and error processing.
282+
283+
```js
284+
const { stream } = await watchStockPrices({
285+
onSseEvent: (event) => {
286+
// access event.data, event.event, event.id, event.retry
287+
},
288+
onSseError: (error) => {
289+
console.error('SSE error:', error);
290+
},
291+
});
292+
```
293+
294+
### Cancellation
295+
296+
Use an `AbortController` to cancel the stream.
297+
298+
```js
299+
const controller = new AbortController();
300+
301+
const { stream } = await watchStockPrices({
302+
signal: controller.signal,
303+
});
304+
305+
// cancel the stream
306+
controller.abort();
307+
```
308+
309+
### Retry
310+
311+
SSE connections automatically reconnect on failure with exponential backoff. You can configure the retry behavior.
312+
313+
```js
314+
const { stream } = await watchStockPrices({
315+
sseDefaultRetryDelay: 3000, // initial retry delay (default: 3000ms)
316+
sseMaxRetryAttempts: 5, // max retry attempts
317+
sseMaxRetryDelay: 30000, // max retry delay cap (default: 30000ms)
318+
});
319+
```
320+
321+
::: tip
322+
Request interceptors registered through `client.interceptors.request` apply to SSE connections, including on each reconnect attempt.
323+
:::
324+
263325
## Build URL
264326

265327
If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

0 commit comments

Comments
 (0)