# ts-fetcheasy

> Fetcheasy library to build declarative API interfaces, based on fetch API

Latest version **1.3.0** (published 2026-02-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install ts-fetcheasy
pnpm add ts-fetcheasy
yarn add ts-fetcheasy
bun add ts-fetcheasy
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2026-02-12 |
| First published | 2023-11-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 59.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | alexbridge |
| Maintainers | alexbridge |
| Keywords | fetch, typescript, decorator, declarative-api |

## Links

- npm: https://www.npmjs.com/package/ts-fetcheasy
- Repository: https://github.com/alexbridge/ts-fetcheasy
- Homepage: https://github.com/alexbridge/ts-fetcheasy#readme
- Issues: https://github.com/alexbridge/ts-fetcheasy/issues
- npm.io page: https://npm.io/package/ts-fetcheasy

## 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

- 1.3.0 (latest) — 2026-02-12
- 1.2.1 — 2024-09-05
- 1.2.0 — 2024-01-26
- 1.1.0 — 2024-01-24
- 1.0.0 — 2023-11-08

## README

## Fetcheasy, declarative typescript API

Decorator based declarative API clients.

### Installation

Install NPM package:

```sh
npm install ts-fetcheasy --save
```

**Limitation:** Min nodejs version is 18.0.0, which have `fetch` API globally available without polyfill, etc.

### Usage

#### Define API (as class)

```ts
import { Get, Json, MediaType, PathParam, Post } from 'fetcheasy';

export class BooksApi {
  @Get({ path: '/books/:id', consumes: MediaType.APPLICATION_JSON })
  async get(@PathParam('id') id: string): Promise<Book> {}

  @Post({ path: '/books', consumes: MediaType.APPLICATION_JSON })
  async add(@Json() jsonData: object): Promise<Book> {}

  @Delete('/books/:id')
  async delete(@PathParam('id') id: string): Promise<Response> {}
}
```

#### Get defined API via factory and use

```ts
const booksApi = FetcheasyApiFactory.builder()
  .baseUrl('http://host')
  .basicAuthentication('test', 'test')
  .build(BooksApi);

// Add new book
let book = booksApi.add({ name: 'book' });
// Get book by id
book = booksApi.get('1');
// Delete book by id
booksApi.delete('1');
```

### Frameworks integrations

#### Nestjs (typescript / nodejs)

```ts
import {
  FetcheasyApiFactory,
  logRequestInterceptor,
  logResponseInterceptor,
} from 'ts-fetcheasy';

@Module({
  providers: [
    {
      provide: BooksApi,
      useFactory: (configService: ConfigService) => {
        return FetcheasyApiFactory.builder()
          .baseUrl(configService.getOrThrow('BASE_PATH'))
          .basicAuthentication(
            configService.getOrThrow('USER'),
            configService.getOrThrow('PASS'),
          )
          .requestInterceptor(logRequestInterceptor)
          .responseInterceptor(logResponseInterceptor)
          .build(BooksApi);
      },
      inject: [ConfigService],
    },
  ],
  exports: [BooksApi],
})
export class BooksModule {}
```

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