# @trapi/client

> A REST client based on axios.

Latest version **2.0.12** (published 2022-08-12) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install @trapi/client
pnpm add @trapi/client
yarn add @trapi/client
bun add @trapi/client
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.12 |
| Published | 2022-08-12 |
| First published | 2022-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 54.7 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Peter Placzek |
| Maintainers | tada5hi |
| Keywords | query, json, json-api, api, rest, api-utils, include, pagination, sort, fields, relations, typescript |

## Links

- npm: https://www.npmjs.com/package/@trapi/client
- Repository: https://github.com/Tada5hi/trapi
- Homepage: https://github.com/Tada5hi/trapi#readme
- Issues: https://github.com/Tada5hi/trapi/issues
- npm.io page: https://npm.io/package/@trapi/client

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.27.2
- [axios-retry](https://npm.io/package/axios-retry.md) ^3.3.1
- [@typescript-error/core](https://npm.io/package/@typescript-error/core.md) ^1.1.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.12 (latest) — 2022-08-12
- 2.0.11 — 2022-07-04
- 2.0.9 — 2022-04-28
- 2.0.8 — 2022-04-27
- 2.0.7 — 2022-04-26
- 2.0.6 — 2022-03-28
- 2.0.5 — 2022-02-21
- 2.0.4 — 2022-02-05
- 2.0.3 — 2022-02-04
- 2.0.2 — 2022-01-27
- 2.0.1 — 2022-01-23
- 2.0.0 — 2022-01-23
- 2.0.0-alpha.0 — 2022-01-22
- 1.0.4 — 2022-01-13
- 1.0.3 — 2022-01-13
- … 2 more at https://npm.io/package/@trapi/client/versions

## README

# TRAPI

[![main](https://github.com/Tada5hi/trapi/actions/workflows/main.yml/badge.svg)](https://github.com/Tada5hi/trapi/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/Tada5hi/trapi/branch/main/graph/badge.svg?token=ZUJ8F5TTSX)](https://codecov.io/gh/Tada5hi/trapi)
[![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/trapi/badge.svg)](https://snyk.io/test/github/Tada5hi/trapi)

**T**ypeScript **R**est **API** generates OpenAPI specifications and API metadata from TypeScript decorators — without locking you into a specific decorator library.

## Why TRAPI?

Most tools that generate OpenAPI from decorators force you to adopt their own decorator set. TRAPI takes a different approach: **bring your own decorators**. You define a mapping from your framework's decorators to TRAPI's metadata model, and TRAPI handles the rest.

- **Decorator-agnostic** — works with any decorator-based HTTP framework (Express, Koa, Fastify, or your own)
- **Pure static analysis** — decorators are no-ops at runtime; metadata is extracted via the TypeScript compiler API
- **Zero runtime overhead** — all work happens at build time, nothing is added to your application
- **Framework presets** — ships with presets for [typescript-rest](https://github.com/thiagobustamante/typescript-rest) and [@decorators/express](https://github.com/serhiisol/node-decorators), or create your own
- **OpenAPI 2.0, 3.0, 3.1 & 3.2** — generates spec-compliant JSON/YAML output

## Packages

| Package | Description |
|---------|-------------|
| [@trapi/core](./packages/core) | Framework-neutral contract: IR types, decorator/preset machinery, authoring helpers (no `typescript` dep) |
| [@trapi/metadata](./packages/metadata) | Extracts API metadata from TypeScript decorators (depends on `@trapi/core`) |
| [@trapi/swagger](./packages/swagger) | Transforms metadata into OpenAPI 2.0, 3.0, 3.1 & 3.2 specifications |
| [@trapi/preset-decorators-express](./packages/preset-decorators-express) | Self-contained preset for @decorators/express (routing + TRAPI markers + JSDoc) |
| [@trapi/preset-typescript-rest](./packages/preset-typescript-rest) | Self-contained preset for typescript-rest (routing + TRAPI markers + JSDoc) |
| [@trapi/cli](./packages/cli) | `trapi` CLI — generate OpenAPI specs straight from the shell |

## Quick Start

```bash
npm install @trapi/metadata @trapi/swagger @trapi/preset-decorators-express @decorators/express
```

```typescript
import { generateMetadata } from '@trapi/metadata';
import { generateSwagger, saveSwagger } from '@trapi/swagger';

// Extract metadata from your decorated TypeScript source
const metadata = await generateMetadata({
    entryPoint: './src/controllers/**/*.ts',
    preset: '@trapi/preset-decorators-express',
});

// Generate OpenAPI spec
const spec = await generateSwagger({
    version: 'v3',
    metadata,
    data: { name: 'My API', version: '1.0.0' },
});

// Write spec to disk
await saveSwagger(spec, { cwd: './docs' });
```

Or skip the script entirely and run it from the shell with [`@trapi/cli`](./packages/cli):

```bash
npx trapi generate \
  --preset @trapi/preset-decorators-express \
  --entry-point 'src/**/*.ts' \
  --output docs/openapi.json \
  --version 3.1
```

## How It Works

TRAPI uses the TypeScript compiler API to statically analyze your source code. It reads decorator metadata from the AST — no `reflect-metadata`, no runtime type information.

```text
TypeScript Source Code  -->  Metadata Extraction  -->  OpenAPI Specification
   (your decorators)        (@trapi/metadata)          (@trapi/swagger)
```

A **preset** is a collection of **handlers** that match decorators by name and mutate a draft (controller, method, parameter, ...). Each handler declares what it matches and how it contributes:

```typescript
import { controller, method } from '@trapi/core';

const controllerHandler = controller({
    match: { name: 'Controller', on: 'class' },
    apply: (ctx, draft) => {
        const arg = ctx.argument(0);
        if (typeof arg?.raw === 'string') {
            draft.path = arg.raw;
        }
    },
});

const getHandler = method({
    match: { name: 'Get', on: 'method' },
    apply: (ctx, draft) => {
        draft.method = 'get';
        const arg = ctx.argument(0);
        if (typeof arg?.raw === 'string') {
            draft.path = arg.raw;
        }
    },
});

export default {
    name: 'my-preset',
    controllers: [controllerHandler],
    methods: [getHandler],
    parameters: [/* ... */],
};
```

Presets can `extend` other presets to inherit and override handlers. The shipped framework presets (`@trapi/preset-decorators-express`, `@trapi/preset-typescript-rest`) are self-contained — each ships its own routing handlers, TRAPI markers, and JSDoc handlers — but a user-authored preset can extend either by name. JSDoc tags use the same model through dedicated `controllerJsDoc` / `methodJsDoc` / `parameterJsDoc` handler arrays.

This means any HTTP framework built on TypeScript decorators can get metadata extraction and OpenAPI generation for free — without changing application code.

## Documentation

The full docs live at [https://trapi.tada5hi.net](https://trapi.tada5hi.net). Highlights:

- **[Quick Start](https://trapi.tada5hi.net/guide/quick-start)** — get an OpenAPI spec on disk in five minutes
- **[Key Concepts](https://trapi.tada5hi.net/guide/concepts)** — the mental model: decorators, mappings, metadata, emitters
- **[Framework Integration](https://trapi.tada5hi.net/guide/framework-integration)** — using TRAPI with typescript-rest, @decorators/express, or your own decorators
- **[CLI](https://trapi.tada5hi.net/guide/cli)** — `trapi generate` from the shell, no script required
- **[Supported TypeScript Types](https://trapi.tada5hi.net/guide/advanced-type-support)** — what the resolver understands
- **[Custom Presets](https://trapi.tada5hi.net/guide/advanced-custom-presets)** — publish a decorator mapping others can reuse
- **[API Reference](https://trapi.tada5hi.net/guide/metadata-api-reference)** — stable public surface for both packages

## License

Made with 💚

Published under [MIT License](./LICENSE).

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