Skip to main content


When building REST APIs, Prisma Client can be used inside your route controllers to send databases queries.

REST APIs with Prisma Client

Supported libraries

As Prisma Client is "only" responsible for sending queries to your database, it can be combined with any HTTP server library or web framework of your choice.

Here's a non-exhaustive list of libraries and frameworks you can use with Prisma ORM:

REST API server example

Assume you have a Prisma schema that looks similar to this:

datasource db {
provider = "sqlite"
url = "file:./dev.db"

generator client {
provider = "prisma-client-js"

model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]

You can now implement route controller (e.g. using Express) that use the generated Prisma Client API to perform a database operation when an incoming HTTP request arrives. This page only shows few sample code snippets; if you want to run these code snippets, you can use a REST API example.


app.get('/feed', async (req, res) => {
const posts = await{
where: { published: true },
include: { author: true },

Note that the feed endpoint in this case returns a nested JSON response of Post objects that include an author object. Here's a sample response:

"id": "21",
"title": "Hello World",
"content": "null",
"published": "true",
"authorId": 42,
"author": {
"id": "42",
"name": "Alice",
"email": ""

POST`/post`, async (req, res) => {
const { title, content, authorEmail } = req.body
const result = await{
data: {
published: false,
author: { connect: { email: authorEmail } },


app.put('/publish/:id', async (req, res) => {
const { id } = req.params
const post = await{
where: { id: Number(id) },
data: { published: true },


app.delete(`/post/:id`, async (req, res) => {
const { id } = req.params
const post = await{
where: {
id: Number(id),

Ready-to-run example projects

You can find several ready-to-run examples that show how to implement a REST API with Prisma Client, as well as build full applications, in the prisma-examples repository.


rest-expressBackend onlyREST API with Express for TypeScript
rest-fastifyBackend onlyREST API using Fastify and Prisma Client.
rest-hapiBackend onlyREST API using hapi and Prisma Client
rest-nestjsBackend onlyNest.js app (Express) with a REST API
rest-nextjs-expressFullstackNext.js app (React, Express) and Prisma Client
rest-nextjs-api-routesFullstackNext.js app (React) with a REST API
rest-nextjs-api-routes-authFullstackImplement authentication using NextAuth.js


rest-expressBackend onlyREST API using Express and Prisma Client
rest-fastifyBackend onlyREST API using Fastify and Prisma Client
rest-nextjsFullstackNext.js app (React) with a REST API
rest-nuxtjsFullstackApp with NuxtJs using Vue (frontend), Express, and Prisma Client