Skip to main content
Version: 2.x

RPC Flavor API

The RPC flavor of API is designed to fully preserve Prisma's query API for both its input and output format. The name "RPC" indicates it's literally like remote procedure calls into a Prisma Client. This API flavor is a good choice if you want to expose Prisma's full power and familiar query syntax to your frontend and care less about API taxonomy.

Here are a few examples of how to use the RPC flavor of API:

// find all posts
GET /api/model/post/findMany
=> [{ id: 1, title: 'Hello World', ... }, ...}]

// find all published posts, the "q" parameter is `{"where":{"published":true}}` url-encoded
GET /api/model/post/findMany?q=%7B%22where%22%3A%7B%22published%22%3Atrue%7D%7D
=> [{ id: 1, title: 'Hello World', ... }, ...}]

// find all posts with their authors, the "q" parameter is `{"include":{"author":true}}` url-encoded
GET /api/model/post/findMany?q=%7B%22include%22%3A%7B%22author%22%3Atrue%7D%7D
=> [{ id: 1, title: 'Hello World', author: { id: 1, name: 'Joey', ... } }, ...}]

// create a post for user#1
POST /api/model/post/create
{
"data": {
"title": "Hello World",
"author": { "connect": { "id": 1 } }
}
}

// update a post
POST /api/model/post/update
{
"where": { "id": 1 },
"data": { "title": "Hello New World!" }
}

// delete a post
DELETE /api/model/post/delete
{
"where": { "id": 1 }
}

You can find the complete API reference here.

In Part IV of this guide, you'll see how to use the auto-generated frontend data query hooks to consume the API, so you don't need to construct the HTTP calls manually.

Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below