> ## Documentation Index
> Fetch the complete documentation index at: https://stars-components.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# @wolfstar/safe-fetch

> Wrap native fetch responses in Result values.

<CodeGroup>
  ```bash npm theme={"system"}
  npm install @wolfstar/safe-fetch
  ```

  ```bash pnpm theme={"system"}
  pnpm add @wolfstar/safe-fetch
  ```

  ```bash yarn theme={"system"}
  yarn add @wolfstar/safe-fetch
  ```

  ```bash bun theme={"system"}
  bun add @wolfstar/safe-fetch
  ```
</CodeGroup>

<CardGroup cols={2}>
  <Card title="npm" icon="npm" horizontal href="https://npmx.dev/package/@wolfstar/safe-fetch" />

  <Card title="Source" icon="github" horizontal href="https://github.com/wolfstar-project/stars-components/tree/main/packages/safe-fetch" />
</CardGroup>

## Description

A fetch wrapper on top of Rust's Result, powered by [`@sapphire/result`](https://www.npmjs.com/package/@sapphire/result).

## Features

* Powered by the native `fetch` function
* CJS and ESM support

## Usage

```typescript theme={"system"}
import { Json, safeFetch } from '@wolfstar/safe-fetch';

const result = await Json<{ id: number; name: string }>(safeFetch('https://api.example.org/users/1'));

result.match({
	ok: (user) => console.log(user.name),
	err: (error) => console.error(error)
});
```
