Skip to content

Introduction

Setup

The default URL pattern is: - CONFIGSERVER_ADDRESS/BRANCH/APP_NAME-PROFILE.json

# expected environment variables:
#
CONFIGSERVER_ADDRESS=http://localhost:8888
BRANCH=master
PROFILE=development
APP_NAME=myapp # field required
CONFIG_FAIL_FAST=True

With fail_fast enabled by default (True) if there is an error when contacting the configuration server SystemExit(1) will be raised. And if the feature is disabled (False) an exception of the type ConnectionError is raised.

Standard output:

http://localhost:8888/master/myapp-development.json

The url pattern can be customize on constructor with parameter url.

from config.spring import ConfigClient

c = ConfigClient(
    app_name='myapp',
    url="{address}/{branch}/{profile}-{app_name}.yaml"
)
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'

Default values

if no value was adjusted for the environment variables below, the default value will be assumed, as:

CONFIGSERVER_ADDRESS=http://localhost:8888
BRANCH=master
PROFILE=development
APP_NAME=
CONFIG_FAIL_FAST=True

Content-Type supported

  • JSON only

Notice

Looks that when request URL sent to Spring Cloud Config Server dosen't have a extension like .json, for example, the server don't load the profile appropriately. If you still want to disable automatic extension inclusion follow the steps reported in: issue-18 or follow steps below.

To reproduce this behavior can you use the docker-compose.yml and make a request to:

# loaded configuration without the appropriate profile
curl http://localhost:8888/master/simpleweb000-development

# loaded configuration with the correct profile
curl http://localhost:8888/master/simpleweb000-development.json 

Example with custom URL:

from config.spring import ConfigClient

c = ConfigClient(
    app_name='myapp',
    url="{address}/{branch}/{profile}-{app_name}.yaml"
)
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'
c.url = c.url[:-5] # << split .json extension
print(c.url)
c.get_config()

Example with standard URL:

from config.spring import ConfigClient

c = ConfigClient(app_name='myapp')
c.url
# OUTPUT: 'http://localhost:8888/master/development-myapp.json'
c.url = c.url[:-5] # << split .json extension
print(c.url)
c.get_config()