This example demonstrates how to get features from a database and use them with Microsoft Feature Management.
To get started,
- Simply run the project
GettingFeaturesFromDatabaseand you should see Swagger UI open in a new browser window. - Try out the
GET /WeatherForecastendpoint and see the response. It should return a successful response (200 OK). - Now, try out
PUT /featureendpoint to set the state of 'Weather' feature flag to 'false'. - Try out the
GET /WeatherForecastendpoint again and see the response. It should return not found response (404 NotFound).
Note: You can get the list of features using GET /feature endpoint.
This example is a simple Web API project with Entity Framework Core and SQLite database.
The endpoints are,
GET /WeatherForecast- This is the endpoint whereFeatureGateattribute is used and access to this endpoint is controlled by the state of 'Weather' feature flag.GET /feature- This is the endpoint to get all the feature flags from the database.PUT /feature- This is the endpoint to update the state of a feature flag in the database. The query parameters are 'featureName' and 'isEnabled'.
During the initial run of the project, an SQLite database file named example.db will be created in the root of GettingFeaturesFromDatabase directory.
Initial run would also create a table named 'Features' and populate it with a feature flag named 'Weather'.
You can find the database seeding logic inside /Database/FeatureConfiguration.cs file.
public void Configure(EntityTypeBuilder<Feature> builder)
{
builder.Property(x => x.Name).IsRequired();
builder.Property(x => x.IsEnabled).IsRequired();
/* Populate with feature data. */
builder.HasData(new List<Feature>()
{
new Feature { Name = FeatureConstants.Weather, IsEnabled = true },
});
builder.ToTable("Features").HasKey(x => x.Name);
}