Skip to content

Commit

Permalink
Add DevCycleService to Nest SDK docs (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura authored Apr 1, 2024
1 parent b68e0f3 commit 4cc958b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion docs/sdk/server-side-sdks/nestjs/nestjs-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4cc958b

Please sign in to comment.