Skip to content
Back to skills

Orpc Nestjs Implement Contract

ASecurity

Implement oRPC contracts in your NestJS projects with @orpc/nest.

  • 8 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 12, 2026
businessnodegitapi

Works with

  • cursor
  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 12, 2026

npx -y skills add ali-master/skills --skill orpc-nestjs-implement-contract --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Nestjs Implement Contract?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Nestjs Implement Contract
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ali-master-orpc-nestjs-implement-contract/badge)](https://www.skillsdirectory.com/skills/ali-master-orpc-nestjs-implement-contract)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC NestJS Implement Contract
description: Implement oRPC contracts in your NestJS projects with @orpc/nest.
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Implement Contract in NestJS

Implement [oRPC contracts](/docs/contract-first/define-contract) in [NestJS](https://nestjs.com/) using `@orpc/nest`.

## Installation

```sh
npm install @orpc/nest@latest
```

## Requirements

oRPC is ESM-only. Configure your NestJS app to support ESM:

```json
{
  "compilerOptions": {
    "module": "NodeNext",
    "strict": true
  }
}
```

- **Node.js 22+**: Recommended — supports `require()` of ESM modules natively.
- **Older versions**: Use a bundler to compile ESM modules to CommonJS.

> NestJS bundler (Webpack/SWC) may not compile `node_modules`. Adjust bundler config to compile `@orpc/nest`.

## Define Your Contract

Each contract **must** define a `path` in `.route` for NestJS implementation. Use `populateContractRouterPaths` to auto-fill paths.

```ts
import { oc, populateContractRouterPaths } from '@orpc/contract'
import * as z from 'zod'

export const PlanetSchema = z.object({
  id: z.number().int().min(1),
  name: z.string(),
  description: z.string().optional(),
})

export const listPlanetContract = oc
  .route({ method: 'GET', path: '/planets' })
  .input(z.object({
    limit: z.number().int().min(1).max(100).optional(),
    cursor: z.number().int().min(0).default(0),
  }))
  .output(z.array(PlanetSchema))

export const contract = populateContractRouterPaths({
  planet: {
    list: listPlanetContract,
    // find, create...
  },
})
```

## Implement Your Contract

```ts
import { Implement, implement, ORPCError } from '@orpc/nest'

@Controller()
export class PlanetController {
  // Standalone procedure
  @Implement(contract.planet.list)
  list() {
    return implement(contract.planet.list).handler(({ input }) => {
      return []
    })
  }

  // Entire contract
  @Implement(contract.planet)
  planet() {
    return {
      list: implement(contract.planet.list).handler(({ input }) => []),
      find: implement(contract.planet.find).handler(({ input }) => ({
        id: 1, name: 'Earth', description: 'The planet Earth',
      })),
      create: implement(contract.planet.create).handler(({ input }) => ({
        id: 1, name: 'Earth', description: 'The planet Earth',
      })),
    }
  }
}
```

## Body Parser

NestJS `urlencoded` parser doesn't support [Bracket Notation](/docs/openapi/bracket-notation). Disable the NestJS body parser:

```ts
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    bodyParser: false,
  })
  await app.listen(process.env.PORT ?? 3000)
}
```

## Configuration

```ts
import { Module } from '@nestjs/common'
import { REQUEST } from '@nestjs/core'
import { onError, ORPCError, ORPCModule } from '@orpc/nest'
import { experimental_RethrowHandlerPlugin as RethrowHandlerPlugin } from '@orpc/server/plugins'

declare module '@orpc/nest' {
  interface ORPCGlobalContext {
    request: Request
  }
}

@Module({
  imports: [
    ORPCModule.forRootAsync({
      useFactory: (request: Request) => ({
        interceptors: [onError(e => console.error(e))],
        context: { request },
        eventIteratorKeepAliveInterval: 5000,
        customJsonSerializers: [],
        plugins: [
          new RethrowHandlerPlugin({
            filter: (error) => !(error instanceof ORPCError),
          })
        ],
      }),
      inject: [REQUEST],
    }),
  ],
})
export class AppModule {}
```

## Type-Safe Client

```ts
import { createORPCClient } from '@orpc/client'
import { OpenAPILink } from '@orpc/openapi-client/fetch'

const link = new OpenAPILink(contract, {
  url: 'http://localhost:3000',
  headers: () => ({ 'x-api-key': 'my-api-key' }),
})

const client: JsonifiedClient<ContractRouterClient<typeof contract>> = createORPCClient(link)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.