The Netlify SDK offers an integration with tRPC, a popular, community-maintained solution for writing queries that offer end-to-end type safety.
tRPC setup files
By default, extensions created by running npm create @netlify/sdk@latest
include all of the boilerplate necessary to write tRPC procedures.
-
The src/server/trpc.ts
file exports a few utilities that are used to build the tRPC router and procedures:
You shouldn’t have to modify this file frequently. You can, however, define reusable procedures here.
-
The src/server/router.ts
file is where you add your tRPC procedures:
Most of your modifications will be made to this file.
-
The src/endpoints/trpc.ts
file initializes an endpoint that serves the tRPC router:
You shouldn’t have to modify this file frequently, either.
-
If you’re building extension UI, the src/ui/trpc.ts
file initializes a tRPC client compatible with React:
This client is used in src/ui/App.tsx
to make tRPC client available to the rest of your extension UI app:
Next steps
For more information on building tRPC procedures (including queries and mutations), refer to the tRPC documentation.
For more information on how to call tRPC endpoints from extension UI, refer to the extension UI endpoints documentation.
Got it!
Your feedback helps us improve our docs.