Skip to main content
Version: 2.x.x

Setup


Initialize Builder

The first step is to initialize the Builder. It manage the basic configuration for connection to the server and all the elements that make up Hyper Fetch, which are instances of - dispatchers, cache and app managers. We start by determining the url of our server.

/src/server/builder.ts
import { Builder } from "@hyper-fetch/core";

export const builder = new Builder({ url: "http://localhost:3000" });

Create Command

Then, having already prepared connection setup for the server, we use the builder method to create commands and assign types to them.

caution

We are using currying to achieve auto generated types for the endpoint string.
This solution will be removed once https://github.com/microsoft/TypeScript/issues/10571 get resolved.

/src/server/auth/auth.ts
import { builder } from "../builder.ts";

type ResponseType = { token: string; refreshToken: string };
type RequestType = { email: string; password: string };

const postLogin = builder.createCommand<ResponseType, RequestType>()({ method: "POST", endpoint: "/auth/login" });

You're ready to use Hyper Fetch! 🎊