# Fumadocs (Framework Mode, React Router): AsyncAPI
URL: /docs/react-router/integrations/asyncapi
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/asyncapi/index.mdx

Generating docs for AsyncAPI schema.

Generate API reference pages from AsyncAPI documents, with a playground for WebSocket and Server-Sent Events. See the [demo](/docs/asyncapi).

<Callout title="AsyncAPI 3 only">
Convert AsyncAPI 2 documents with `npx @asyncapi/cli convert`.
</Callout>

## Setup [#setup]

Install the required packages.

```npm
npm i @fumadocs/asyncapi shiki
```

### Generate Styles [#generate-styles]

Add the following line:

```css title="Tailwind CSS"
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
/* [!code ++] */
@import '@fumadocs/asyncapi/css/preset.css';
```

### Configure Plugin [#configure-plugin]

Create the AsyncAPI server instance and the `<AsyncAPIPage />` component.

```ts tab="lib/asyncapi.ts"
import { createAsyncAPI } from '@fumadocs/asyncapi/server';

// note: this is a server-side API
export const asyncapi = createAsyncAPI({
  // the AsyncAPI schema, you can also give it an external URL.
  input: ['./asyncapi.yaml'],
});
```

```tsx tab="components/api-page.tsx"
'use client';
import { createAsyncAPIPage } from '@fumadocs/asyncapi/ui';

export const AsyncAPIPage = createAsyncAPIPage();
```

See [`createAsyncAPI()`](/docs/react-router/integrations/asyncapi/server) and [`createAsyncAPIPage()`](/docs/react-router/integrations/asyncapi/api-page) for their options.

### Generate Pages [#generate-pages]

Pass `staticSource()` to your [`loader()`](/docs/headless/source-api/source). It generates pages without writing files.

`staticSource()` reads files, so `source.ts` becomes server-only. Move `docs` into `collections.ts` for client code to import.

```ts tab="app/lib/source.ts"
import { loader } from 'fumadocs-core/source';
import { defineDocs } from 'fumadocs-mdx/macro'; // [!code --]
// [!code ++:2]
import { docs } from '@/lib/collections';
import { asyncapi } from '@/lib/asyncapi';

// [!code --:6]
export const docs = defineDocs({
  dir: 'content/docs',
  docs: {
    async: true,
  },
});

// server-only now, as `staticSource()` reads files [!code ++]
export const source = loader(
  // [!code ++:6]
  {
    docs: docs.toFumadocsSource(),
    asyncapi: await asyncapi.staticSource({
      baseDir: 'asyncapi',
    }),
  },
  {
    baseUrl: '/docs',
    // [!code ++:2] optional: adds the direction of messages to each page item in page tree
    plugins: [asyncapi.loaderPlugin()],
  },
);
```

```ts tab="app/lib/collections.ts"
import { defineDocs } from 'fumadocs-mdx/macro';

export const docs = defineDocs({
  dir: 'content/docs',
  docs: {
    async: true,
  },
});
```

`staticSource()` generates a page per operation by default. See [Generating Pages](/docs/react-router/integrations/asyncapi/generate-files) to customize them.

**Pages of `source` now have two types, `docs` and `asyncapi`.** Update every place that uses `source`, like where you return text for LLMs:

```ts
import { llms } from 'fumadocs-core/source';
import { source } from '@/lib/source';

export const docsLlms = llms(source, {
  renderPage: async (page) => {
    // [!code ++:3]
    if (page.type === 'asyncapi') {
      return `# ${page.data.title}\n\n${await page.data.getText('processed')}`;
    }

    // your original flow below...
  },
});
```

Render AsyncAPI pages with `<AsyncAPIPage />` in your docs page:

```tsx title="app/routes/docs.tsx"
import { docs, source } from '@/lib/source'; // [!code --]
// [!code ++:3]
import { docs } from '@/lib/collections';
import { source } from '@/lib/source';
import { AsyncAPIPage } from '@/components/api-page';

export async function loader({ params }: Route.LoaderArgs) {
  const slugs = params['*'].split('/').filter((v) => v.length > 0);
  const page = source.getPage(slugs);
  if (!page) throw new Response('Not found', { status: 404 });

  // [!code ++:9]
  const pageTree = await source.serializePageTree(source.getPageTree());
  if (page.type === 'asyncapi') {
    return {
      type: 'asyncapi' as const,
      title: page.data.title,
      props: page.data.getAsyncAPIPageProps(),
      pageTree,
    };
  }

  return { type: 'docs' as const, path: page.path, pageTree }; // [!code highlight]
}

export default function Page({ loaderData }: Route.ComponentProps) {
  const data = useFumadocsLoader(loaderData);

  return (
    <DocsLayout {...baseOptions()} tree={data.pageTree}>
      {/* [!code ++:8] */}
      {data.type === 'asyncapi' && (
        <DocsPage full>
          <DocsTitle>{data.title}</DocsTitle>
          <DocsBody>
            <AsyncAPIPage {...data.props} />
          </DocsBody>
        </DocsPage>
      )}
      {/* [!code highlight] */}
      {data.type === 'docs' && <Content path={data.path} />}
    </DocsLayout>
  );
}
```

<Callout type="warn" title="Ensure the migration is complete!">
Run a type check before continuing:

```npm
npm run types:check
```
</Callout>

To write MDX files into your content directory instead, see [MDX Files](/docs/react-router/integrations/asyncapi/generate-files#mdx-files).