---
title: "Build a Typesafe API with tRPC and Deno"
description: "tRPC lets a Deno server and client share types through an exported router type, with no schema declarations or code generation."
url: "https://swe.quest/articles/build-a-typesafe-api-with-trpc-and-deno-9411ac01cbda8497"
canonical: "https://deno.com/blog/build-typesafe-apis-trpc"
source: "Deno"
published: "2024-11-19"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["typescript","rpc","api-design","javascript"]
---

# Build a Typesafe API with tRPC and Deno

A post on [Deno](https://swe.quest/sources/deno.md), published 2024-11-19, 7 min read, How-to. Original: [https://deno.com/blog/build-typesafe-apis-trpc](https://deno.com/blog/build-typesafe-apis-trpc)

## Summary

tRPC lets a Deno server and client share types through an exported router type, with no schema declarations or code generation. The tutorial installs tRPC v11 and Zod from npm, then builds a file-backed dinosaur API with query, mutation and async-iterable streaming procedures, served by tRPC's standalone HTTP adapter. The client uses splitLink with the batch-stream and subscription links and gets compile-time checking from the imported AppRouter type. Passing a number instead of a string shows Zod rejecting the input at runtime with an invalid\_type error.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [RPC & gRPC](https://swe.quest/tags/rpc.md) (Backend & APIs)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- TypeScript basics ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- HTTP APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

tRPC, Deno, Zod, Deno 2, JSR

## Related posts

- [Build a REST API with Express, TypeScript, and Deno](https://swe.quest/articles/build-a-rest-api-with-express-typescript-and-deno-803b55a783fab19e.md): Deno · 2023-03-08 · Medium · 5 min read · TypeScript, JavaScript, API design, Runtimes & VMs
  Deno runs Express with TypeScript without any TypeScript build configuration: Express is imported through an npm: specifier and its types are pulled in with a @deno-types comment.
- [Build a dinosaur runner game with Deno, pt. 1](https://swe.quest/articles/build-a-dinosaur-runner-game-with-deno-pt-1-e4d3faa91fec67fd.md): Deno · 2025-12-08 · Medium · 5 min read · JavaScript, TypeScript, Deployment, Serverless
  Part one of a series building a browser dinosaur runner game sets up a Deno project that serves static files and deploys it.
- [Build a SolidJS app with Deno](https://swe.quest/articles/build-a-solidjs-app-with-deno-74660014c869b9ff.md): Deno · 2024-12-05 · Medium · 7 min read · Frontend, JavaScript, TypeScript
  A dinosaur catalog app built with SolidJS on the frontend and a Hono API on Deno, scaffolded with Vite via \`deno init --npm\` and dependencies added from JSR and npm with \`deno add\`.
- [How to Build a GraphQL Server with Deno](https://swe.quest/articles/how-to-build-a-graphql-server-with-deno-b4bf15abf8edf07f.md): Deno · 2023-01-11 · Medium · 7 min read · GraphQL, TypeScript, PostgreSQL, API design
  A GraphQL API server can be built in Deno with the std HTTP Server, the gql middleware, graphql\_tools' makeExecutableSchema and graphql\_tag.
- [Build a REST API with Express, TypeScript, and Deno, pt. 2](https://swe.quest/articles/build-a-rest-api-with-express-typescript-and-deno-pt-2-e71cec39c5b23268.md): Deno · 2023-04-06 · Medium · 4 min read · TypeScript, Testing, Containers, API design
  An Express REST API running on Deno gets integration tests via Deno.test using fetch against a configurable staging URL, and HTTP latency benchmarks via Deno.bench in a \_bench file.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
