Skip to content
RESN
GitHub

tRPC

  • The new backend NodeJS project using tRPC
  • tRPC does not use standard API endpoints; instead, it provides a fully typed client to the frontend that allows for full-stack type-safety
  • Adding an endpoint is as simple as adding a new function to the backend router, then using the new client method in the frontend project

Example

Backend

import { publicProcedure, router } from "../trpc";

export const miscRouter = router({
	ping: publicProcedure.query(() => {
		return "Pong!";
	}),
});

Frontend

import { trpc } from "$lib/client";

const data = trpc().misc.ping.query();
console.log(data);

File structure

  • Most modules are for endpoints (e.g. src/live/, src/users/) that correspond to the services that are provided on the RESN frontend.
  • The files typically seen within modules have the following extensions:
    • .router.ts: Contains the tRPC router and all endpoints
    • .emails.ts: Contains email sending logic
    • .utils.ts: Contains other related utility functions