# @contentgrid/typed-fetch

> Add typing information to fetch() requests and responses

Latest version **0.4.4** (published 2026-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @contentgrid/typed-fetch
pnpm add @contentgrid/typed-fetch
yarn add @contentgrid/typed-fetch
bun add @contentgrid/typed-fetch
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.4 |
| Published | 2026-09-28 |
| First published | 2023-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Maintainers | xenit-jenkins |
| Keywords | fetch, typescript |

## Links

- npm: https://www.npmjs.com/package/@contentgrid/typed-fetch
- Repository: https://github.com/xenit-eu/contentgrid-ts
- Homepage: https://github.com/xenit-eu/contentgrid-ts#readme
- Issues: https://github.com/xenit-eu/contentgrid-ts/issues
- npm.io page: https://npm.io/package/@contentgrid/typed-fetch

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.6.1
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^8.0.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

- 0.4.4 (latest) — 2026-09-28
- 0.4.2 — 2025-03-24
- 0.4.1 — 2024-10-18
- 0.4.0 — 2024-07-08
- 0.3.0 — 2024-04-03
- 0.2.0 — 2023-09-28
- 0.1.0 — 2023-08-09

## README

# `@contentgrid/typed-fetch`

Typed `fetch()` requests and responses using Typescript.

## Usage

This library is most useful when used with other code that provides a `TypedRequestSpec` which describes the shape of the request and response body.

```typescript
import { TypedRequestSpec, request, Representation, fetch as typedFetch } from '@contentgrid/typed-fetch'


namespace myLibrary {
    // This is example code that describes the hypothetical library.
    // Note that the library *knows* the request and response format of POST http://example.com/string-size and has created types for them

    export interface StringSizeRequest {
        string: string;
    }

    export interface StringSizeResponse {
        string: string;
        length: number;
    }

    export function stringSizeRequest(): TypedRequestSpec<StringSizeRequest, StringSizeResponse> {
        return {
            method: "POST",
            uri: "http://example.com/string-size"
        }
    }
}


// Retrieve a TypedRequestSpec somewhere
const requestSpec = myLibrary.stringSizeRequest();

// Create a Request
const request = request(requestSpec, {
    // The type of 'body' is type-checked so it confirms to `StringSizeRequest`
    body: Representation.json({
        string: "abc"
    }),
    // All other standard fetch Request options are valid here, except for 'method'
});


(async () => {
    // Perform the request, just like a standard fetch()
    const response = await typedFetch(request);

    if(response.ok) {
        const data = await response.json(); // Type is `StringSizeResponse`
        console.log(data.length);
    }

}())

```

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