# yaschema-ws-api-client

> Client supporting WebSockets via yaschema-ws-api

Latest version **4.2.3** (published 2025-09-15) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install yaschema-ws-api-client
pnpm add yaschema-ws-api-client
yarn add yaschema-ws-api-client
bun add yaschema-ws-api-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.2.3 |
| Published | 2025-09-15 |
| First published | 2023-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 113.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | bwestphal |
| Keywords | schema, typescript, client, server, node, browser, websocket |

## Links

- npm: https://www.npmjs.com/package/yaschema-ws-api-client
- Repository: https://github.com/TypeScript-OSS/yaschema-ws-api-client
- Homepage: https://typescript-oss.github.io/yaschema-ws-api-client/
- Issues: https://github.com/TypeScript-OSS/yaschema-ws-api-client/issues
- npm.io page: https://npm.io/package/yaschema-ws-api-client

## Dependencies (3)

- [yaschema](https://npm.io/package/yaschema.md) ^5.2.2
- [yaschema-api](https://npm.io/package/yaschema-api.md) ^5.0.5
- [yaschema-ws-api](https://npm.io/package/yaschema-ws-api.md) ^4.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 4.2.3 (latest) — 2025-09-15
- 4.2.2 — 2025-05-13
- 4.2.1 — 2025-05-09
- 4.2.0 — 2025-04-30
- 4.1.10 — 2025-04-19
- 4.1.9 — 2025-04-11
- 4.1.8 — 2025-04-05
- 4.1.7 — 2025-03-02
- 4.1.6 — 2025-02-18
- 4.1.5 — 2025-01-16
- 4.1.4 — 2025-01-06
- 4.1.3 — 2024-12-06
- 4.1.2 — 2024-12-06
- 4.1.1 — 2024-11-26
- 4.1.0 — 2024-11-15
- … 30 more at https://npm.io/package/yaschema-ws-api-client/versions

## README

# yaschema-ws-api-client

[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

Client supporting WebSockets via yaschema-ws-api

## Basic Example

```typescript
export const stream = makeWsApi({
  routeType: 'stream',
  url: '/stream',
  schemas: {
    requests: {
      ping: schema.object({ echo: schema.string().allowEmptyString().optional() }).optional()
    },
    responses: {
      pong: schema.object({
        body: schema.string()
      })
    }
  }
});
```

```typescript
const connection = await apiWs(
  stream,
  {},
  {
    pong: async ({ input }) => {
      console.log(`GOT ${input.body}`)
    }
  }
);

await connection.output.ping({ echo: 'Hello World!' });
```

The above example demonstrates basic use of a yaschema-ws-api-client, which lets you define runtime and compile-time types for bidirectionally working with WebSockets.  See the [express-yaschema-ws-api-handler](https://www.npmjs.com/package/express-yaschema-ws-api-handler) package for adding handlers to Express.

This library supports web-based WebSockets by default and supports the Node [ws](https://www.npmjs.com/package/ws) package by calling:

```typescript
setWebSocket(WebSocket as any as CommonWebSocket);
```

While the Node ws WebSocket interface doesn't perfectly align with the web equivalent, for the aspects we use, it does.

## Thanks

Thanks for checking it out.  Feel free to create issues or otherwise provide feedback.

[API Docs](https://typescript-oss.github.io/yaschema-ws-api-client/)

Be sure to check out our other [TypeScript OSS](https://github.com/TypeScript-OSS) projects as well.

<!-- Definitions -->

[downloads-badge]: https://img.shields.io/npm/dm/yaschema-ws-api-client.svg

[downloads]: https://www.npmjs.com/package/yaschema-ws-api-client

[size-badge]: https://img.shields.io/bundlephobia/minzip/yaschema-ws-api-client.svg

[size]: https://bundlephobia.com/result?p=yaschema-ws-api-client

---
_Source: https://npm.io/package/yaschema-ws-api-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
