Skip to content
← All posts

Why I moved my side projects from REST to tRPC

1 min read#nextjs #typescript

The problem with my REST setup

Every side project started the same way: an Express API, a React frontend, and a types file I copied between them by hand. They drifted apart within a week.

server/routers/expense.ts
export const expenseRouter = router({
  add: protectedProcedure
    .input(z.object({ amount: z.number(), note: z.string() }))
    .mutation(async ({ ctx, input }) => {
      // fully typed on the client, no copy-paste
      return ctx.db.expense.create({ data: input });
    }),
});

Migrating one route at a time

I kept the old REST routes running and moved one feature per evening. Each migrated route deleted a chunk of hand-written types.

When I'd still pick REST

When other teams or the public call the API, a documented REST or OpenAPI contract is worth the extra typing.