-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exposed JSON endpoint for Waffle flag/switch/sample state (#452)
Adds a JSON endpoint that returns the state of all flags/switches/samples. In addition to the state, the endpoint also includes the last-modified time, which can be useful to identify stale flags that may need to be cleaned up.
- Loading branch information
1 parent
c5d5646
commit 5d8f55c
Showing
6 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ JavaScript. | |
mixins | ||
templates | ||
javascript | ||
json | ||
cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. _usage-json: | ||
|
||
===================== | ||
Waffle Status as JSON | ||
===================== | ||
|
||
Although :doc:`WaffleJS<javascript>` returns the status of all | ||
:ref:`flags <types-flag>`, :ref:`switches <types-switch>`, and | ||
:ref:`samples <types-sample>`, it does so by exposing a Javascript | ||
object, rather than returning the data in a directly consumable format. | ||
|
||
In cases where a directly consumable format is preferrable, | ||
Waffle also exposes this data as JSON via the ``waffle_status`` view. | ||
|
||
|
||
Using the view | ||
-------------- | ||
|
||
Using the ``waffle_status`` view requires adding Waffle to your URL | ||
configuration. For example, in your ``ROOT_URLCONF``:: | ||
|
||
urlpatterns = patterns('', | ||
(r'^', include('waffle.urls')), | ||
) | ||
|
||
This adds a route called ``waffle_status``, which will return the current | ||
status of each flag, switch, and sample as JSON, with the following structure: | ||
|
||
.. code-block:: json | ||
{ | ||
"flags": { | ||
"flag_active": { | ||
"is_active": true, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
}, | ||
"flag_inactive": { | ||
"is_active": false, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
} | ||
}, | ||
"switches": { | ||
"switch_active": { | ||
"is_active": true, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
}, | ||
"switch_inactive": { | ||
"is_active": false, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
} | ||
}, | ||
"samples": { | ||
"sample_active": { | ||
"is_active": true, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
}, | ||
"sample_inactive": { | ||
"is_active": false, | ||
"last_modified": "2020-01-01T12:00:00.000" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.urls import path | ||
|
||
from waffle.views import wafflejs | ||
from waffle.views import wafflejs, waffle_json | ||
|
||
urlpatterns = [ | ||
path('wafflejs', wafflejs, name='wafflejs'), | ||
path('waffle_status', waffle_json, name='waffle_status'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters