Output
Every generated file in your output folder is created by a plugin. This page describes the default output, but similar logic applies to all plugins.
Overview
If you use the default configuration, your project might look like this.
my-app/
├── node_modules/
├── src/
│ ├── client/
│ │ ├── client/
│ │ ├── core/
│ │ ├── client.gen.ts
│ │ ├── index.ts
│ │ ├── sdk.gen.ts
│ │ └── types.gen.ts
│ └── index.ts
└── package.json
Your actual output depends on your Hey API configuration. It may contain a different number of files and their contents might differ.
Let's go through each file in the src/client
folder and explain what it looks like, what it does, and how to use it.
Client
client.gen.ts
is generated by client plugins. If you choose to generate SDKs (enabled by default), we use the Fetch client unless specified otherwise.
import { createClient, createConfig } from './client';
export const client = createClient(createConfig());
The contents of this file are consumed by SDKs, but you can also import client
in your application to perform additional configuration or send manual requests.
Bundle
Client plugins provide their bundles inside client
and core
folders. The contents of these folders don't depend on the provided input. Everything inside these folders serves as a scaffolding so the generated code can make HTTP requests.
TypeScript
You can learn more on the TypeScript page.
SDK
You can learn more on the SDK page.
Barrel File
index.ts
is not generated by any specific plugin. It's meant for convenience and by default, it re-exports every artifact generated by default plugins (TypeScript and SDK).
export * from './sdk.gen';
export * from './types.gen';
Disable index file
We recommend importing artifacts from their respective files to avoid ambiguity, but we leave this choice up to you.
import type { Pet } from './client';
// or
import type { Pet } from './client/types.gen';
If you're not importing artifacts from the index file, you can skip generating it altogether by setting the output.indexFile
option to false
.
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: {
indexFile: false,
path: 'src/client',
},
};
Re-export more files
You can choose which files should be re-exported by setting the exportFromIndex
option to true
on any plugin. For example, here's how you would re-export Zod plugin exports.
export default {
input: 'hey-api/backend', // sign up at app.heyapi.dev
output: 'src/client',
plugins: [
// ...other plugins
{
exportFromIndex: true,
name: 'zod',
},
],
};
WARNING
Re-exporting additional files from index file may result in broken output due to naming conflicts.
Examples
You can view live examples on StackBlitz.
Sponsors
Help Hey API stay around for the long haul by becoming a sponsor.