Problem statement
Build a REST API that reports feature flags declared as beans and configured from properties.
Requirements
FlagConfig
There are three feature flags, darkMode, betaSearch, and newCheckout, each with a default value in application.properties under its own property key.
- Turn this class into a configuration class and declare each of the three flags as a separate bean in it
- The FeatureFlag type is not a scanned component, so component scanning will not create these beans; each flag must be declared explicitly as a bean in this class
- For each flag, read its default enabled state from its property and create a FeatureFlag whose name is the flag name and whose enabled state is that property value:
- darkMode reads property flags.dark-mode
- betaSearch reads property flags.beta-search
- newCheckout reads property flags.new-checkout
- If a property is missing, the flag defaults to disabled
FlagController
Collect the declared FeatureFlag beans through the constructor, then implement the endpoint.
GET /flags
- Return 200 OK with a JSON object mapping every flag's name to its boolean enabled state
- Each flag's reported state is whatever its property resolves to, so changing a property value changes the response with no code change
Sample Requests & Responses
Expand to view details on sample requests and responses.
GET /flags
Response (200 OK):
{
"darkMode": true,
"betaSearch": false,
"newCheckout": false
}
