# express-yaschema-api-handler

> Express handler support for yaschema-api

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

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

## Install

```sh
npm install express-yaschema-api-handler
pnpm add express-yaschema-api-handler
yarn add express-yaschema-api-handler
bun add express-yaschema-api-handler
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.2.5 |
| Published | 2025-09-15 |
| First published | 2023-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 183.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | bwestphal |
| Keywords | schema, typescript, express, server |

## Links

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

## Dependencies (4)

- [multer](https://npm.io/package/multer.md) ^2.0.2
- [yaschema](https://npm.io/package/yaschema.md) ^5.2.2
- [yaschema-api](https://npm.io/package/yaschema-api.md) ^5.0.5
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^2.3.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.2.5 (latest) — 2025-09-15
- 4.2.4 — 2025-05-13
- 4.2.3 — 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
- … 54 more at https://npm.io/package/express-yaschema-api-handler/versions

## README

# express-yaschema-api-handler

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

Express support for handling APIs declared using yaschema-api.

## Basic Example

```typescript
// API schema and metadata
// You'll typically define this in a separate package shared by your server and clients
export const postPing = makeHttpApi({
  method: 'POST',
  routeType: 'rest',
  url: '/ping',
  isSafeToRetry: true,
  schemas: {
    request: {
      body: schema.object({
        echo: schema.string().allowEmptyString().optional()
      })
    },
    successResponse: {
      status: schema.number(StatusCodes.OK),
      body: schema.string()
    }
  }
});
```

```typescript
// Register the API handler with Express
export const register = (app: Express & YaschemaApiExpressContextAccessor) =>
  registerHttpApiHandler(app, postPing, {}, async ({ express: _express, input, output }) => {
    output.success(200, { body: (input.body.echo?.length ?? 0) > 0 ? `PONG ${input.body.echo ?? ''}` : 'PONG' });
  });
```

The options object passed to `registerHttpApiHandler` lets you override the validation mode and/or specify middleware.

### Initializing Multiple Express Servers Simultaneously

If you happen to be potentially initializing multiple Express servers simultaneously (e.g. on different ports) and you're using Yaschema API for more than one of these servers, you will need to extend your `Express` instance to support `YaschemaApiExpressContextAccessor` by calling `addYaschemaApiExpressContextAccessorToExpress(express, context)` before calling `registerHttpApiHandler` (or `register`, in the above example) -- where `context` should be unique for each Express server, and can be created using `makeYaschemaApiExpressContext`.

## Thanks

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

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

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/express-yaschema-api-handler.svg

[downloads]: https://www.npmjs.com/package/express-yaschema-api-handler

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

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

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