Repositories
appconfigsa
Published by: Configfacets0Updated

Examples of application configurations aligned with Configfacet's core concepts.

applications
coreconcepts
|

Authentication

Add API authentication details

HEADERS
X-APIKEY
string
Send X-APIKEY in Header

Readme

User instructions for this resource

Configfacets Example: Environment-Based Configuration

Below is a Configfacets example demonstrating a configuration type that adapts based on the deployment environment of the API Service. This service requires RabbitMQ, Redis, Elasticsearch, and S3 bucket details, which vary by environment. Additionally, feature flags control how configuration details are retrieved.

Requirements

EnvironmentDescription
DevelopmentDevelopers run the codebase locally. Backend developers must configure RabbitMQ while disabling other integrations like Elasticsearch using feature flags.
StagingDeployed in an internal cluster managed by the company's operations team, including Elasticsearch, RabbitMQ, and Redis.
Production (AWS East & West)The application runs across AWS East and West Coast data centers. API services in both regions share a common Redis instance but maintain separate S3 buckets and Elasticsearch instances.

Design Considerations

  1. Default Configuration
{
    "name": "API Service",
    "facets": [
        "master"
    ],
    "features": {
        "is_s3_enabled": false,
        "is_redis_enabled": false,
        "is_rabbitmq_enabled": false,
        "is_elasticsearch_enabled": false
    },
    "rabbitmq": {
        "port": "{{ rabbitmq_port }}"
    }
}
  • All integrations (RabbitMQ, Redis, etc.) are disabled by default.
  • Common values across environments are stored in facet:master, ensuring they are included regardless of the facet filters clients use.
  1. Development Environment
{
    "facets": [
        "env:dev"
    ],
    "features": {
        "is_rabbitmq_enabled": true
    },
    "rabbitmq": {
        "host": "127.0.0.1"
    }
}
  • RabbitMQ is expected to run locally, so integration is enabled with specific configuration details.
  1. Staging Environment
{
    "facets": [
        "env:nonprod",
        "cluster:internal"
    ],
    "features": {
        "is_rabbitmq_enabled": true
    },
    "rabbitmq": {
        "host": "10.0.0.32"
    }
}
  • Used by the CI/CD pipeline and deployed with a shared RabbitMQ instance.
  1. Production Environment (AWS)
{
    "facets": [
        "env:prod"
    ],
    "features": {
        "is_s3_enabled": true,
        "is_redis_enabled": true,
        "is_rabbitmq_enabled": true,
        "is_elasticsearch_enabled": true
    }
},
{
    "s3": {
        "bucket": "my_app_bucket"
    },
    "redis": {
        "host": "mycachecluster.abcdef.ng.0001.use1.cache.amazonaws.com",
        "port": "{{ redis_port }}"
    },
    "facets": [
        "env:prod",
        "cluster:aws"
    ]
}
  • Uses a shared Redis instance and a common S3 bucket name across data centers.
  • All features are enabled by default.
  • Configuration is split into two sections for better clarity and for merging logic see Core Concepts.
  1. Production (East/West Deployment)
{
    "s3": {
        "host": "https://s3.us-east-1.amazonaws.com"
    },
    "facets": [
        "env:prod",
        "cluster:aws",
        "region:east"
    ],
    "rabbitmq": {
        "host": "rabbitmq.cabcdefghijk.us-east-1.rds.amazonaws.com"
    },
    "elasticsearch": {
        "host": "https://search-myapp-abcdefg12345.us-east-1.es.amazonaws.com"
    }
},
{
    "s3": {
        "host": "https://s3.us-west-1.amazonaws.com"
    },
    "facets": [
        "env:prod",
        "cluster:aws",
        "region:west"
    ],
    "rabbitmq": {
        "host": "rabbitmq.cabcdefghijk.us-west-1.rds.amazonaws.com"
    },
    "elasticsearch": {
        "host": "https://search-myapp-abcdefg12345.us-west-1.es.amazonaws.com"
    }
}
  • Each region has its own RabbitMQ, Elasticsearch, and S3 bucket instances.

This structure ensures that configurations are modular, environment-specific, and efficiently managed using facet-based filtering.

Interactive Examples

Explore above links and use Try out to check interactive examples.

Usages

You can use any HTTP client in your preferred programming language to interact with Configfacets.

Currently, Configfacets provides a Python & NPM client, but we're open to supporting additional languages. If you're interested, feel free to reach out to us on our Discord channel.

Python

pip install configfacets

Example Usage in Python

from configfacets.configuration import Configuration

config = Configuration(
    source="https://configfacets.com/apis/repos/configfacets/core-concepts/appconfigs/resources/collections/api-configurations/exec?format=json",
    sourceType="url",
    apiKey="<your_api_key>",
    postBody={"facets":["env:prod","cluster:aws","region:east"]},
)
config.fetch()
resp = config.get_resp()

isS3Enabled = config.get_value("features.is_s3_enabled")

print("Is S3 enabled:{}".format(isS3Enabled))

NPM

npm install configfacets

Example Usage in NPM

import Configfacets from "configfacets";

(async () => {
  const config = new Configfacets(
    "https://configfacets.com/apis/repos/configfacets/core-concepts/appconfigs/resources/collections/api-configurations/exec?format=json",
    "url",
    "<your_api_key>",
    { facets: ["env:prod","cluster:aws","region:east"] }
  );

  await config.fetch();
  console.log(
    "Is S3 enabled:",
    config.getValue("features.is_s3_enabled")
  );
})();

GO

Refer to the Go client repository for setup and example usage.

For a raw cURL request, check the cURL tab below.

POST/apis/repos/configfacets/core-concepts/appconfigs/resources/collections/api-configurations/exec
REQUEST
QUERY-STRING PARAMETERS
format
string
No sources available.
API Server https://configfacets.com
API Key
Not set
RESPONSES
No content available.