diff --git a/docs/sdk/server-side-sdks/nestjs/nestjs-usage.md b/docs/sdk/server-side-sdks/nestjs/nestjs-usage.md index 98b0c56a..42476f4f 100644 --- a/docs/sdk/server-side-sdks/nestjs/nestjs-usage.md +++ b/docs/sdk/server-side-sdks/nestjs/nestjs-usage.md @@ -35,9 +35,50 @@ export class MyController { } ``` +## DevCycle Service +With the DevCycleModule imported, the `DevCycleService` can be injected into your controllers or providers. The DevCycleService methods evaluate variables with the user returned from your [userFactory](/sdk/server-side-sdks/nestjs/nestjs-gettingstarted#user-factory), so you don't need to specify a user each time a method is called. + +```typescript +import { DevCycleService } from '@devcycle/nestjs-server-sdk' + +export class MyService { + constructor( + private readonly devcycleService: DevCycleService, + ) {} + + async update() { + const enabled = this.devcycleService.isEnabled('allow-feature-edits') + if (enabled) { + // do something + } + } +} +``` + +### variableValue +The `variableValue` method accepts a variable key and default value, and returns the served value. + +```typescript +const value = this.devcycleService.variableValue('variable-key', 'hello world') +``` + +### isEnabled +The `isEnabled` method accepts a key for a boolean variable. The default value is always `false` when using the `isEnabled` method. + +```typescript +const enabled = this.devcycleService.isEnabled('boolean-variable') +``` + +### getUser +The `getUser` method returns the user object from your [userFactory](/sdk/server-side-sdks/nestjs/nestjs-gettingstarted#user-factory). + +```typescript +const devcycleUser = this.devcycleService.getUser() +``` + ## Decorators -DevCycle decorator evaluate variables with the user returned from your [userFactory](/sdk/server-side-sdks/nestjs/nestjs-gettingstarted#user-factory), so you don't need to specify a user each time a decorator is used. +DevCycle decorators evaluate variables with the user returned from your [userFactory](/sdk/server-side-sdks/nestjs/nestjs-gettingstarted#user-factory), so you don't need to specify a user each time a decorator is used. ### VariableValue The `VariableValue` decorator can be used to access variable values directly in your route handlers.