This is a simple web application that allows users to search for books using the Google Books API. The application displays the search results with pagination and provides additional information such as the total number of results, the most common author, the earliest publication date, the latest publication date, and the server response time.
We'll use the app and some of its features to explore the value of the LaunchDarkly platform.
- Search for books using the Google Books API
- Display search results with pagination
- Show additional information about the search results
- Responsive and accessible design
Before you begin, ensure you have the following installed on your machine:
Follow these instructions to get a copy of the project up and running on your local machine.
git clone [email protected]:nicolemichelle88/googlebooks_featureflags.git
cd googlebooks_featureflags-
Create a Virtual Environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the Required Packages:
pip3 install -r requirements.txt
-
Configure LaunchDarkly Keys in Your Code:
Replace placeholders in your
app.pyandscripts.jswith your actual keys:- In
scripts.js, replace with your LaunchDarkly client-side ID online 16:const clientSideId = '<your-client-side-ID>'; // Replace with your actual client-side ID
- CLIENT_SIDE_ID: Found in your LaunchDarkly Client-side SDK Keys
- In
-
Set Environment Variables:
export LD_SDK_KEY=your_sdk_key export LD_API_KEY=your_ld_api_key export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/slack/webhook
Note: You can find your LaunchDarkly keys as follows:
- LD_SDK_KEY: Found in your LaunchDarkly Project Settings
- LD_API_KEY: Found in your LaunchDarkly API Access Tokens
- SLACK_WEBHOOK_URL: See Copy the Webhook URL in the below section on Setting Up Slack
-
Run the Flask App:
python3 app.py
The backend server will start on
http://127.0.0.1:5000.
- Open the
index.htmlfile in the browser of your choice!
-
Enter a Search Query:
In the search input, type the name of a book, author, or any keyword you want to search for.
-
Click Search:
Click the "Search" button or press Enter to start the search. The search results will be displayed with pagination controls.
-
Navigate Through Pages:
Use the "Previous" and "Next" buttons to navigate through the pages of search results. Click on the page numbers to jump to a specific page.
Create a Feature Flag:
- Go to your LaunchDarkly dashboard.
- Create a two new feature flags with a
booleanflag type:first-buttonandlast-button. - Name the variations
TrueandFalse. - The end result should look like this:
Create a Segment:
- Go to your LaunchDarkly dashboard.
- Create a new user segment and add the users who should be included. In this case, target anyone whose username contains
beta. - The end result should look like this:
Create Rules for Individual Targeting
- Navigate inside the Dashboard for the
last-buttonFlag - Click
Add Ruleand selectTarget Individuals - Set the rule to serve
truetouser1andfalsetouser2
Create Rules for Rule-Based Targeting
-In the same Dashboard for the last-button Flag, click Add Rule again, but this time choose Target Segments:
-
Set the rule "If not in
betagroup, flag=false" by choosing theis not inoperator and thebetasegment you previously created. Serve rollout asfalse.
-
The end result should look like this:
Set Up Metrics:
- Go to your LaunchDarkly dashboard.
- Create a new metric to track the desired events. In this example, we're seeting up the metric
fetch-page-erroras in the screenshot below. Ensure you've gotfetch-page-erroras theEvent KeyandLower than Baselineas theSuccess Criteria. - The end result should look like this before you click
Create Metric:
Navigate to the Slack API page at https://api.slack.com/.
- Click on "Create New App."
- Select "From scratch."
- Provide a name for your app and choose the Slack workspace where you want to install the app.
- Click "Create App."
In the sidebar, under "Features," click on "Incoming Webhooks."
Toggle the switch to "Activate Incoming Webhooks."
- Click on "Add New Webhook to Workspace."
- Select a channel where the webhook will post messages and click "Allow."
- After allowing, you will be redirected back to the app settings page.
- You will see your new webhook URL under "Webhook URLs for Your Workspace."
- Copy this URL. It will be used in your Flask application to send messages to Slack.
- Ensure that you are using Python 3 by using
python3andpip3commands to avoid any confusion with Python 2.x. - Make sure you install the required Python packages using the
requirements.txtfile to avoid missing dependencies.
pip3 install -r requirements.txtBy following these steps, you should be able to set up and run the Google Books Search App with feature flags using LaunchDarkly. If you encounter any issues or have any questions, feel free to reach out to me for support!

