# API patterns (Prisma ORM v7) (/docs/orm/v7/core-concepts/api-patterns)

> For the complete Prisma documentation index, see [llms.txt](/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL.

How to use Prisma ORM with REST APIs, GraphQL servers, and fullstack frameworks

Location: ORM > v7 > Core Concepts > API patterns

Prisma Client can be used to query your database from any server-side JavaScript or TypeScript application. This page covers common patterns for REST APIs, GraphQL servers, and fullstack frameworks.

## REST APIs

When building REST APIs, use Prisma Client inside your route controllers to execute database queries.

### Supported frameworks

- [Express](https://expressjs.com/)
- [Fastify](https://fastify.dev/)
- [hapi](https://hapi.dev/)
- [koa](https://koajs.com/)
- [NestJS](https://nestjs.com/)
- [Next.js API Routes](https://nextjs.org/)

### Example routes

```ts
// GET /feed - fetch published posts
app.get("/feed", async (req, res) => {
  const posts = await prisma.post.findMany({
    where: { published: true },
    include: { author: true },
  });
  res.json(posts);
});

// POST /post - create a post
app.post("/post", async (req, res) => {
  const { title, content, authorEmail } = req.body;
  const result = await prisma.post.create({
    data: {
      title,
      content,
      author: { connect: { email: authorEmail } },
    },
  });
  res.json(result);
});

// PUT /publish/:id - publish a post
app.put("/publish/:id", async (req, res) => {
  const post = await prisma.post.update({
    where: { id: Number(req.params.id) },
    data: { published: true },
  });
  res.json(post);
});

// DELETE /post/:id - delete a post
app.delete("/post/:id", async (req, res) => {
  const post = await prisma.post.delete({
    where: { id: Number(req.params.id) },
  });
  res.json(post);
});
```

## GraphQL

Prisma ORM works with any GraphQL library. Use Prisma Client inside your resolvers to read and write data.

### Supported tools

| Library         | Purpose        |
| :-------------- | :------------- |
| `graphql-yoga`  | HTTP server    |
| `apollo-server` | HTTP server    |
| `pothos`        | Schema builder |
| `nexus`         | Schema builder |
| `type-graphql`  | Schema builder |

### Framework integrations

- [Redwood.js](https://rwsdk.com/) - Built on Prisma ORM

### Prisma's role

Prisma ORM is used inside GraphQL resolvers the same way you'd use any other ORM:

- **Queries**: Read data from the database to return in the response
- **Mutations**: Write data to the database (create, update, delete)

## Fullstack frameworks

Fullstack frameworks blur server/client boundaries. Use Prisma Client in the server-side portion of your application.

### Supported frameworks

- [Next.js](https://nextjs.org/)
- [Remix](https://remix.run)
- [SvelteKit](https://svelte.dev/)
- [Nuxt](https://nuxt.com/)
- [Redwood](https://rwsdk.com/)
- [Wasp](https://wasp-lang.dev/)

### Supported runtimes

- [Node.js](https://nodejs.org/)
- [Bun](https://bun.sh/)
- [Deno](https://deno.com/)

### Next.js example

```ts
// In getServerSideProps or API routes
export const getServerSideProps = async () => {
  const feed = await prisma.post.findMany({
    where: { published: true },
  });
  return { props: { feed } };
};
```

## Example projects

Find ready-to-run examples in the [`prisma-examples`](https://github.com/prisma/prisma-examples/) repository:

| Example                                      | Type      | Description                    |
| :------------------------------------------- | :-------- | :----------------------------- |
| [Next.js](https://pris.ly/e/orm/nextjs)      | Fullstack | Next.js 15 app                 |
| [Express](https://pris.ly/e/ts/rest-express) | REST      | Express REST API               |
| [Fastify](https://pris.ly/e/ts/rest-fastify) | REST      | Fastify REST API               |
| [GraphQL Yoga](https://pris.ly/e/ts/graphql) | GraphQL   | GraphQL server with Pothos     |
| [NestJS](https://pris.ly/e/ts/rest-nestjs)   | REST      | NestJS REST API                |
| [Remix](https://pris.ly/e/ts/remix)          | Fullstack | Remix with actions and loaders |
| [SvelteKit](https://pris.ly/e/ts/sveltekit)  | Fullstack | SvelteKit app                  |

## Related pages

- [`Data modeling`](/guides/core-concepts-v7-data-modeling): Learn how data modeling with Prisma differs from data modeling with SQL or ORMs. Prisma uses a declarative data modeling language to describe a database schema
- [`Overview`](/guides/core-concepts-v7-supported-databases): Prisma ORM supports PostgreSQL, MySQL, SQLite, MongoDB, SQL Server, CockroachDB, and serverless databases

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
