Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app router example on readme.md #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ app.use("/panel", (_, res) => {

`trpc-panel` just renders as a string, so it can be used with any backend.

## NextJS / create-t3-app example
## NextJS pages router / create-t3-app example

In Nextjs you'd want to create an api route somewhere like `src/pages/api/panel.ts` and send a text response:

Expand All @@ -63,6 +63,31 @@ export default async function handler(_: NextApiRequest, res: NextApiResponse) {

Then we can visit the url `http://localhost:3000/api/panel` to use the panel. Here we do `transformer: "superjson"` assuming we have `superjson` set as the transformer in tRPC (which create-t3-app does by default).

## NextJS app router / create-t3-app example

In Nextjs you'd want to create an api route somewhere like `src/app/api/panel/route.ts` and send a text response:

```ts
import { renderTrpcPanel } from "trpc-panel";
import { appRouter } from "../../server/api/root";

async function handler() {
return new Response(
renderTrpcPanel(appRouter, {
url: "http://localhost:3000/api/trpc",
transformer: "superjson",
}),
{
headers: {'Content-Type': 'text/html'}
}
);
}

export const { POST: handler, GET: handler }
```

Then we can visit the url `http://localhost:3000/api/panel` to use the panel. Here we do `transformer: "superjson"` assuming we have `superjson` set as the transformer in tRPC (which create-t3-app does by default).

## Documenting Procedures

As of v1.1.0, `trpc-panel` supports documenting procedures.
Expand Down