DEV Community

Alex Spinov
Alex Spinov

Posted on

tRPC Has a Free API You Should Know About

tRPC lets you build fully typesafe APIs without schemas, code generation, or REST. Define your backend function and call it from the frontend — with full TypeScript autocompletion.

Why tRPC Eliminates API Boilerplate

A full-stack developer was maintaining OpenAPI specs, generating client SDKs, and manually keeping types in sync between frontend and backend. With tRPC, they deleted all of that — the frontend just calls backend functions directly with full type safety.

Key Features:

  • End-to-End Type Safety — No code generation needed
  • Autocompletion — Full IDE support on client and server
  • Framework Agnostic — Works with Next.js, Nuxt, SvelteKit, Express
  • Subscriptions — Real-time with WebSockets
  • Batching — Automatic request batching

Quick Start

npm install @trpc/server @trpc/client
Enter fullscreen mode Exit fullscreen mode

Server

import { initTRPC } from "@trpc/server"
import { z } from "zod"

const t = initTRPC.create()

const appRouter = t.router({
  hello: t.procedure
    .input(z.string())
    .query(({ input }) => `Hello ${input}!`),

  createUser: t.procedure
    .input(z.object({ name: z.string(), email: z.string().email() }))
    .mutation(({ input }) => db.user.create({ data: input }))
})

export type AppRouter = typeof appRouter
Enter fullscreen mode Exit fullscreen mode

Client

import { createTRPCClient } from "@trpc/client"
import type { AppRouter } from "./server"

const trpc = createTRPCClient<AppRouter>({ /* config */ })

// Full autocompletion!
const greeting = await trpc.hello.query("World")
const user = await trpc.createUser.mutate({ name: "Alice", email: "alice@example.com" })
Enter fullscreen mode Exit fullscreen mode

Why Choose tRPC

  1. Zero boilerplate — no schemas, no codegen, no OpenAPI specs
  2. Type safety — catch errors at compile time, not runtime
  3. Developer experience — autocomplete for every API call

Check out tRPC docs to get started.


Building APIs? Check out my Apify actors or email spinov001@gmail.com for custom data extraction solutions.

Top comments (0)