Only Support tRPC 10
This project provides an adapter for integrating tRPC (TypeScript RPC) with Azure Functions v4. The adapter simplifies the process of setting up type-safe and efficient APIs using TypeScript and tRPC within the Azure Functions environment.
npm install trpc-azure-functions-adapter
// filename: `src/trpc.ts`
import { AzureFuncContextOption } from 'trpc-azure-functions-adapter';
import { inferAsyncReturnType, initTRPC } from '@trpc/server';
export function createContext({ context, request }: AzureFuncContextOption) {
return {
context,
request,
};
}
const t = initTRPC.context<typeof createContext>().create();
const publicProcedure = t.procedure;
export const appRouter = t.router({
greet: publicProcedure
.query(({ input, ctx }) => {
console.log(ctx.request.params);
return `Greetings, `;
}),
});
export type AppRouter = typeof appRouter;
// filename: `src/main.ts`
import { createAzureFunctionsHandler } from 'trpc-azure-functions-adapter';
import { appRouter, createContext } from './trpc';
import { app } from '@azure/functions';
app.http('trpc', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
route: 'trpc/{*proxy}',
handler: createAzureFunctionsHandler({
router: appRouter,
createContext,
}),
});
This project is licensed under the MIT License
Contributions are welcome!
If you encounter any issues or have questions, please open an issue on the Issues tab.