Skip to Content
TypeScript SDKServe

Vite

Run hypequery next to a Vite frontend and proxy API requests in development.

This guide assumes you already have:

  • a Vite + React app
  • an api/queries.ts file exporting api
  • a running hypequery server process

If not, start with Quick Start.

Proxy API requests in development

Update vite.config.ts:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:4000',
        changeOrigin: true,
      },
    },
  },
});

Generate typed React hooks

Generate the route manifest, so the hooks know each endpoint's method and path:

npm install @hypequery/react @tanstack/react-query
npm install -D @hypequery/cli
npx hypequery generate:manifest api/queries.ts --output src/lib/hypequery-manifest.json

Create src/lib/hypequery.ts:

import { createHooks } from '@hypequery/react';
import type { InferApiType } from '@hypequery/serve';
import type { api } from '../../api/queries';
import manifest from './hypequery-manifest.json';

type Api = InferApiType<typeof api>;

export const { useQuery, useMutation } = createHooks<Api>({
  baseUrl: '/api/analytics',
  manifest,
});

Both server imports are import type, so no server code reaches the Vite bundle. Serve mounts routes under /api/analytics by default, which the /api proxy above forwards. Re-run generate:manifest when you add or re-route a query. Projects created by hypequery init also export ApiDefinition, the same InferApiType<typeof api> type.

Wrap the app with QueryClientProvider

import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import App from './App';

const queryClient = new QueryClient();

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <QueryClientProvider client={queryClient}>
      <App />
    </QueryClientProvider>
  </StrictMode>
);

Use Node.js or Fetch Runtime Integration for the server process that hosts api.handler.

On this page

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.