Framework Integration Guides
Drift injects VCAP_SERVICES and VCAP_APPLICATION environment variables into every app — the same format used by Cloud Foundry. Most frameworks have libraries that read these automatically, giving you zero-config service binding.
How it works
drift bind-service, Drift generates a VCAP_SERVICES JSON object containing credentials for every bound service. Your app reads this at startup — no config files, no secrets management needed.VCAP_SERVICES Reference#
Each service type produces credentials in a specific format. Here's what Drift generates for each marketplace service, based on the actual broker implementation.
PostgreSQL#
{
"postgres": [{
"name": "mydb",
"label": "postgres",
"plan": "small",
"tags": ["postgres"],
"credentials": {
"hostname": "drift-pg-abc12345",
"port": 5432,
"name": "db_1a2b3c4d5e6f7g8h",
"username": "u_5e6f7g8h1a2b3c4d",
"password": "...",
"uri": "postgres://u_5e6f7g8h1a2b3c4d:...@drift-pg-abc12345:5432/db_1a2b3c4d5e6f7g8h"
}
}]
}MySQL#
{
"mysql": [{
"name": "mydb",
"label": "mysql",
"plan": "small",
"tags": ["mysql"],
"credentials": {
"hostname": "drift-mysql-abc12345",
"port": 3306,
"name": "db_1a2b3c4d5e6f7g8h",
"username": "u_5e6f7g8h1a2b3c4d",
"password": "...",
"uri": "mysql://u_5e6f7g8h1a2b3c4d:...@drift-mysql-abc12345:3306/db_1a2b3c4d5e6f7g8h",
"jdbc_url": "jdbc:mysql://drift-mysql-abc12345:3306/db_1a2b3c4d5e6f7g8h"
}
}]
}MongoDB#
{
"mongodb": [{
"name": "mydb",
"label": "mongodb",
"plan": "small",
"tags": ["mongodb"],
"credentials": {
"hostname": "drift-mongo-abc12345",
"port": 27017,
"name": "db_1a2b3c4d5e6f7g8h",
"username": "u_5e6f7g8h1a2b3c4d",
"password": "...",
"uri": "mongodb://u_5e6f7g8h1a2b3c4d:...@drift-mongo-abc12345:27017/db_1a2b3c4d5e6f7g8h?authSource=admin"
}
}]
}Redis#
{
"redis": [{
"name": "mycache",
"label": "redis",
"plan": "small",
"tags": ["redis"],
"credentials": {
"hostname": "drift-redis-abc12345",
"port": 6379,
"password": "...",
"uri": "redis://:...@drift-redis-abc12345:6379"
}
}]
}RabbitMQ#
{
"rabbitmq": [{
"name": "myqueue",
"label": "rabbitmq",
"plan": "small",
"tags": ["rabbitmq"],
"credentials": {
"hostname": "drift-rmq-abc12345",
"port": 5672,
"management_port": 15672,
"username": "u_5e6f7g8h1a2b3c4d",
"password": "...",
"vhost": "v_1a2b3c4d5e6f7g8h",
"uri": "amqp://u_5e6f7g8h1a2b3c4d:...@drift-rmq-abc12345:5672/v_1a2b3c4d5e6f7g8h",
"management_uri": "http://drift-rmq-abc12345:15672"
}
}]
}Spring Boot — Zero-Config Service Binding#
Spring Boot's java-cfenv library automatically detects VCAP_SERVICES and configures your DataSource, Redis, RabbitMQ, MongoDB, and more — with zero application code changes. Since Drift produces the exact same VCAP format as Cloud Foundry, it works out of the box.
Step 1 — Add java-cfenv#
Maven:
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>3.1.5</version>
</dependency>Gradle:
implementation 'io.pivotal.cfenv:java-cfenv-boot:3.1.5'Step 2 — Create & bind services#
drift create-service postgres small mydb
drift bind-service myapp mydb
drift restart myappStep 3 — That's it!#
java-cfenv automatically:
- Detects the
VCAP_SERVICESenvironment variable - Finds matching service bindings by type (postgres, mysql, redis, etc.)
- Sets the corresponding Spring properties — no
application.ymldatabase config needed
Zero-config application.yml
# No datasource config needed — java-cfenv reads VCAP_SERVICES!
spring:
jpa:
hibernate:
ddl-auto: updateAuto-Configuration Mapping#
Here's what java-cfenv configures for each Drift service type:
| Drift Service | java-cfenv Processor | Spring Properties Set |
|---|---|---|
| postgres | CfJdbcService | spring.datasource.url / username / password |
| mysql | CfJdbcService | spring.datasource.url / username / password |
| mongodb | CfMongoService | spring.data.mongodb.uri |
| redis | CfRedisService | spring.data.redis.host / port / password |
| rabbitmq | CfRabbitService | spring.rabbitmq.host / port / username / password |
MySQL bonus: jdbc_url
jdbc_url credential field (jdbc:mysql://...) for frameworks that need a JDBC connection string directly.Advanced — Manual VCAP_SERVICES Parsing#
If you prefer not to use java-cfenv, Spring Boot automatically flattens VCAP_SERVICES into properties you can inject:
@Value("${vcap.services.mydb.credentials.uri}")
private String databaseUri;
@Value("${vcap.services.mydb.credentials.username}")
private String dbUsername;Node.js / Express#
Using the cfenv package#
npm install cfenvconst cfenv = require('cfenv');
const appEnv = cfenv.getAppEnv();
// Get postgres credentials by service instance name
const pgService = appEnv.getServiceCreds('mydb');
// pgService = { hostname, port, name, username, password, uri }
const { Pool } = require('pg');
const pool = new Pool({ connectionString: pgService.uri });Manual parsing#
const vcapServices = JSON.parse(process.env.VCAP_SERVICES || '{}');
const pgCreds = vcapServices.postgres?.[0]?.credentials;
if (pgCreds) {
const { Pool } = require('pg');
const pool = new Pool({ connectionString: pgCreds.uri });
}Python / Django / Flask#
Using python-cfenv#
pip install cfenvfrom cfenv import AppEnv
env = AppEnv()
pg = env.get_service(label='postgres')
DATABASE_URL = pg.credentials['uri']Django settings.py#
import json, os
vcap = json.loads(os.environ.get('VCAP_SERVICES', '{}'))
if 'postgres' in vcap:
creds = vcap['postgres'][0]['credentials']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': creds['hostname'],
'PORT': creds['port'],
'NAME': creds['name'],
'USER': creds['username'],
'PASSWORD': creds['password'],
}
}Flask with SQLAlchemy#
import json, os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
vcap = json.loads(os.environ.get('VCAP_SERVICES', '{}'))
if 'postgres' in vcap:
app.config['SQLALCHEMY_DATABASE_URI'] = vcap['postgres'][0]['credentials']['uri']
db = SQLAlchemy(app)Go#
Direct VCAP_SERVICES parsing#
import (
"encoding/json"
"os"
)
type VCAPServices map[string][]struct {
Name string `json:"name"`
Credentials map[string]interface{} `json:"credentials"`
}
func getServiceCreds(serviceName string) map[string]interface{} {
var services VCAPServices
json.Unmarshal([]byte(os.Getenv("VCAP_SERVICES")), &services)
for _, instances := range services {
for _, inst := range instances {
if inst.Name == serviceName {
return inst.Credentials
}
}
}
return nil
}
// Usage:
// creds := getServiceCreds("mydb")
// uri := creds["uri"].(string)Docker / Generic#
Any application in any language can read VCAP_SERVICES — it's just a JSON environment variable.
# Extract the postgres URI with jq
export DATABASE_URL=$(echo $VCAP_SERVICES | jq -r '.postgres[0].credentials.uri')
# Or use it inline
echo $VCAP_SERVICES | jq '.postgres[0].credentials'Shell-based extraction
jq, you can use python3 -c as an alternative JSON parser since Python is available in most base images.# Without jq — using python3
export DATABASE_URL=$(python3 -c "import json,os; print(json.loads(os.environ['VCAP_SERVICES'])['postgres'][0]['credentials']['uri'])")