Framework Integration
Patterns for using com.candescent.forge:di-java-sdk in long-running servers and serverless functions.
Spring Boot
Create one CandescentClient bean at application startup and reuse it across requests:
import com.candescent.di.CandescentClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CandescentConfig {
@Bean(destroyMethod = "close")
public CandescentClient candescentClient() {
return CandescentClient.fromEnv();
}
}
Inject the client into your controllers or services:
import com.candescent.di.CandescentClient;
import com.candescent.di.generated.model.AccountsResponse;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/accounts")
public class AccountsController {
private final CandescentClient client;
public AccountsController(CandescentClient client) {
this.client = client;
}
@GetMapping("/{userId}")
public AccountsResponse listAccounts(@PathVariable String userId) throws Exception {
return client.accounts()
.callList()
.hostUserId(userId)
.execute();
}
}
The SDK caches OAuth tokens internally, so a singleton client is safe for concurrent requests in a single JVM.
AWS Lambda
For short-lived handlers, use standalone operations from com.candescent.di.operations so you do not manage the client lifecycle in every invocation. Each helper reads CANDESCENT_* environment variables and handles client setup internally — see SDK Reference → Standalone operations.
Set CANDESCENT_CLIENT_ID, CANDESCENT_CLIENT_SECRET, CANDESCENT_INSTITUTION_ID, and CANDESCENT_ENVIRONMENT in the Lambda environment configuration (or AWS Secrets Manager).
For Lambdas that make many calls per invocation, a static CandescentClient singleton is also acceptable — reuse the client across repeated invocations when AWS keeps your function running, and call close() only if the runtime supports graceful shutdown.
Lifecycle guidelines
| Pattern | When to use |
|---|---|
Singleton CandescentClient | Spring Boot, long-running workers |
com.candescent.di.operations helpers | Lambda, one-off CLI scripts |
client.close() | Process shutdown, test teardown |
Production credentials
Do not commit .env files or ship Client ID / Client Secret in source control. Use your platform's secret store in deployed environments.
- Local development — shell exports or IDE run configuration (see Examples)
- Deployed environments — environment variables, AWS Secrets Manager, Azure Key Vault, or your platform's secret store
- Developer Console — rotate Client ID / Secret if credentials are exposed
Obtain credentials via the Getting Started quickstart guide.
Related guides
- Quick Start — first client setup
- SDK Reference — standalone operations and error types
- Troubleshooting — auth and runtime issues