trpc-azure-functions-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

tRPC Adapter for Azure Functions v4

CI

In Development process, done for Proof of concept considering adding feature for production use

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.

Installation

npm install trpc-azure-functions-adapter

Usage

1. Create a router.ts file

// filename: `src/router.ts`

import { AzureFuncContextOption } from 'trpc-azure-functions-adapter';
import { inferAsyncReturnType, initTRPC } from '@trpc/server';

export function createContext({ context, request }: AzureFuncContextOption) {
  return {
    context,
    request,
  };
}

type Context = inferAsyncReturnType<typeof createContext>;

const t = initTRPC.context<Context>().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;

2. Create an Azure Functions entry file, e.g., trpc.ts

// filename: `src/functions/trpc.ts`

import { azureFunctionsRequestHandler } from 'trpc-azure-functions-adapter';
import { appRouter, createContext } from '../router';

azureFunctionsRequestHandler({
  router: appRouter,
  createContext,
});

License

This project is licensed under the MIT License

Acknowledgments

Contributing

Contributions are welcome!

Issues

If you encounter any issues or have questions, please open an issue on the Issues tab.

Other Option:

Readme

Keywords

Package Sidebar

Install

npm i trpc-azure-functions-adapter

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

21.5 kB

Total Files

8

Last publish

Collaborators

  • mildronize