Skip to content

Commit 2957832

Browse files
committed
chore: update NestJS readme with a simple example of how to implement the RequiredFlagsController
Signed-off-by: Kaushal Kapasi <[email protected]>
1 parent bffdb8a commit 2957832

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/nest/README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ yarn add @openfeature/nestjs-sdk @openfeature/server-sdk @openfeature/core
7272

7373
The following list contains the peer dependencies of `@openfeature/nestjs-sdk` with its expected and compatible versions:
7474

75-
* `@openfeature/server-sdk`: >=1.7.5
76-
* `@nestjs/common`: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
77-
* `@nestjs/core`: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
78-
* `rxjs`: ^6.0.0 || ^7.0.0 || ^8.0.0
75+
- `@openfeature/server-sdk`: >=1.7.5
76+
- `@nestjs/common`: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
77+
- `@nestjs/core`: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0
78+
- `rxjs`: ^6.0.0 || ^7.0.0 || ^8.0.0
7979

8080
The minimum required version of `@openfeature/server-sdk` currently is `1.7.5`.
8181

@@ -152,6 +152,24 @@ export class OpenFeatureTestService {
152152
}
153153
```
154154

155+
#### Managing Controller or Route Access via Feature Flags
156+
157+
The `RequireFlagsEnabled` decorator can be used to manage access to a controller or route based on the enabled state of a feature flag. The decorator will throw an exception if the required feature flag(s) are not enabled.
158+
159+
```ts
160+
import { Controller, Get } from '@nestjs/common';
161+
import { RequireFlagsEnabled } from '@openfeature/nestjs-sdk';
162+
163+
@Controller()
164+
export class OpenFeatureController {
165+
@RequireFlagsEnabled({ flags: [{ flagKey: 'testBooleanFlag' }] })
166+
@Get('/welcome')
167+
public async welcome() {
168+
return 'Welcome to this OpenFeature-enabled NestJS app!';
169+
}
170+
}
171+
```
172+
155173
## Module additional information
156174

157175
### Flag evaluation context injection

0 commit comments

Comments
 (0)