Skip to content

Commit 5a0cde7

Browse files
committed
updated readme
1 parent 2eb8d6b commit 5a0cde7

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

README.md

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,53 @@
11
# ob-dj-feature-flags
22

3-
ob-dj-feature-flags is a Django package for managing feature flags and controlling access to Django views & API endpoints using decorators.
3+
Feature flags are a powerful technique that allows you to enable/disable specific features in your application without deploying new code. This gives you the ability to control the behavior of your application dynamically and perform A/B testing, read more about feature flags [here](https://www.atlassian.com/continuous-delivery/principles/feature-flags).
4+
5+
ob-dj-feature-flags provides a simple way to create and manage feature flags within your Django admin panel. It also provides decorators for views and viewsets to easily control access based on feature flags.
46

57
## Features
68

79
- Create and manage feature flags within your Django admin panel.
8-
- Decorators for views and viewsets to easily control access based on feature flags.
9-
- Caching mechanism to improve performance when checking feature flag status.
10-
- Management command to scan viewsets and actions to populate the feature flags automatically (coming soon).
11-
12-
### Overview
10+
- Add decorators to views and viewsets to control access based on the created feature flags.
11+
- Caching mechanism to reduce database hits when checking feature flag statuses.
12+
- Feature flags endpoint to use the same feature flags in your client apps.
13+
- Skip feature flags during tests or in the entire project.
1314

14-
```python
15-
from ob_dj_feature_flags.utils.decorators import class_feature_flag, action_feature_flag
16-
17-
@class_feature_flag("todos")
18-
class TodosViewSet(
19-
mixins.CreateModelMixin,
20-
mixins.ListModelMixin,
21-
viewsets.GenericViewSet,
22-
):
23-
permission_classes = [
24-
permissions.AllowAny,
25-
]
26-
queryset = Todo.objects.all()
27-
serializer_class = TodosSerializer
28-
29-
@action_feature_flag("todos_list")
30-
def list(self, request, *args, **kwargs):
31-
return super().list(request, *args, **kwargs)
32-
33-
@action_feature_flag("todos_create")
34-
def create(self, request, *args, **kwargs):
35-
return super().create(request, *args, **kwargs)
36-
```
15+
## Setup & Installation
3716

38-
In this example, the TodosViewSet class is decorated with `@class_feature_flag("todos")`, which checks if the 'todos' feature flag is active before allowing access to any actions within the viewset.
17+
1. Use pip to install ob-dj-feature-flags:
3918

40-
Additionally, the list() method is decorated with `@action_feature_flag("todos_list")`, which checks if the 'todos_list' feature flag is active before allowing access to the list action. Similarly, the create() method is decorated with `@action_feature_flag("todos_create")`, which checks if the 'todos_create' feature flag is active before allowing access to the create action.
19+
```shell
20+
pip install ob-dj-feature-flags
21+
```
4122

42-
By combining both class-level and action-level feature flags, you can control access to the entire viewset based on the 'todos' flag, as well as control access to specific actions within the viewset based on the corresponding flags ('todos_list' and 'todos_create' in this example).
23+
2. Add "ob_dj_feature_flags" to your `INSTALLED_APPS` setting like this:
4324

44-
## Installation
25+
```python
26+
# settings.py
27+
INSTALLED_APPS = [
28+
...
29+
"ob_dj_feature_flags.core.flags",
30+
]
31+
```
4532

46-
Use pip to install ob-dj-feature-flags:
33+
3. If you plan to use the created feature flags in your client apps, add the feature flags endpoint to your project's urls.py:
4734

48-
```shell
49-
pip install ob-dj-feature-flags
35+
```python
36+
# urls.py
37+
urlpatterns = [
38+
...
39+
path('ob-dj-feature-flags/', include('ob_dj_feature_flags.apis.flags.urls')),
40+
]
5041
```
5142

43+
4. Run `python manage.py migrate` to create the feature flags table.
44+
5245
## Usage
5346

5447
### Creating Feature Flags
5548

5649
Define feature flags in your Django project using the provided FeatureFlag admin. Each feature flag has a unique name and an active status.
5750

58-
5951
### Decorating Views
6052

6153
Use the `@action_feature_flag` decorator to control access to individual views based on feature flags. Apply the decorator to the desired view functions or class-based views. Example:
@@ -90,9 +82,9 @@ This will check if the 'my_feature_flag' is active before allowing access to any
9082

9183
Integrating feature flags into your client apps allows you to control the behavior and enable/disable specific features dynamically. To leverage feature flags in your client app, follow these simple steps:
9284

93-
1. At the startup time of your client app make a GET request to the feature flags endpoint of your backend API (`/flags/` by default).
85+
1. Make a GET request to the feature flags endpoint of your backend API (preferably at startup) `ob-dj-feature-flags/` (check step 3 of Setup & Installation section).
9486
2. The endpoint will provide a JSON response containing the list of feature flags along with their statuses.
95-
3. Store the feature flags and their statuses in your client app.
87+
3. Store the feature flags and their statuses somewhere in your client app.
9688
4. Use the feature flags to control the behavior of your client app (you can create a wrapper function or a custom hook to simplify this process).
9789

9890
## Skipping Feature Flags During Tests

0 commit comments

Comments
 (0)