Demo Curl
Access configuration data with curl.
1. Simple access configuration data with curl
This section describes, how configuration data can be retrieved with a simple curl command.
- login to configseeder, create configuration group curl test
- create an api key with access permission for the created configuration group and all environments (this is not required, you can limit the access permission how to the minimum)
- add the following values to curl test:
-
execute curl:
export API_KEY=xxx <- Add API Key here
curl -X POST -H "Authorization: Bearer $API_KEY" \
-H "Content-type: application/json" \
-H "Accept: text/x-java-properties" -d '{
"tenantKey": "demo",
"environmentKey": "TEST",
"configurations": [
{
"configurationGroupKey": "curl_demo"
}
]
}' 'https://demo.configseeder.com/external/configurations?download=false'
The result will be something like:
#Export
#Sun Apr 07 15:08:23 GMT 2019
service.name=My Service
service.password=test-password
service.url=https\://test-service/api
service.username=serviceuser
If you change the accept-header to text/yaml you will get:
service:
password: test-password
name: My Service
url: https://test-service/api
username: serviceuser
2. Use templating feature with curl
Imagine you need a configuration file which contains an url, username and password. Depending on the environment you want your application to connect to the configuration values have to be changed.
For this example, you need exactly the same configuration group which was created in the first example. Then you create a configuration file config-template.xml with the following content:
<config>
<service url="${service.url}"
username="${service.username}"
password="${service.password}" />
</config>
And a request.json:
{
"configurations": [
{
"configurationGroupKey": "curl_demo",
"selectionMode": "LATEST"
}
],
"environmentKey": "TEST",
"tenantKey": "demo"
}
When you execute curl …
export API_KEY=xxx <- Add API Key here
curl -X POST \
--header "Authorization: Bearer $APIKEY" \
--header 'Content-Type: multipart/form-data' \
--form "configuration=@request.json;type=application/json" \
--form "template=@config-template.xml" \
--output config.xml \
"https://demo.configseeder.com/external/configurations/replace?variablePrefix=%24%7B&variablePostfix=%7D"
… you should get a config.xml with the following content:
<config>
<service url="https://test-service/api"
username="serviceuser"
password="test-password" />
</config>
If you change TEST to PROD in your request.json and execute the curl again, you will get the configuration for the Production environment.