Skip to content

ofetch

ofetch is a HTTP client for Node.js and browsers. We created a plugin for easily connect ofetch to your services and sending HTTP requests for your needs.

Install

You can install the @nixle/ofetch package using npm, pnpm, yarn, or bun:

sh
npm i @nixle/ofetch
sh
pnpm add @nixle/ofetch
sh
yarn add @nixle/ofetch
sh
bun i @nixle/ofetch

Setup

To use ofetch in your services, you need to add the ofetchPlugin to the plugins array when creating the app.

ts
import { createApp } from 'nixle';
import { ofetchPlugin } from '@nixle/ofetch';

const app = createApp({
  plugins: [
    ofetchPlugin({
      // Any ofetch options such as base url, headers, etc.
    }),
  ],
});

Usage

To use ofetch in your services, you can use the ofetch function that is available in the service context.

ts
import { createService } from 'nixle';

const usersService = createService('users', ({ ofetch }) => {
  const getUsers = async () => {
    const data = await ofetch('/users');

    return data;
  };

  return {
    getUsers,
  };
});