Flutter + HTTP

This guide describes how to integrate the DataDome Plugin for Flutter.

Pub

Installation

To install the plugin, add the DataDome dependency to your pubspec.yaml:

dependencies:
  datadome: ^1.2.0
  flutter:
    sdk: flutter

Note: Make sure your project does support Swift/Kotlin. If not, enable Swift/Kotlin for your Flutter project by executing the following command:

flutter create -i swift -a kotlin

For iOS:

Update the Info.plist file of the iOS project under ios/Runner/Info.plist:

  1. Add a new entry with the key DataDomeKey and your DataDome client side key as value.
  2. Add a new entry with the key DataDomeProxyEnabled and NO as value (make sure the type of the entry is Boolean).

Now the plugin is ready to be used.

Usage

Initialize the DataDome client

Create an instance of the DataDome client.

DataDome client = DataDome('YOUR_DATADOME_CLIENT_SIDE_KEY');

Perform HTTP requests

Use HTTP methods from the DataDome client to perform the request.

Here a sample code to perform a POST request

//importing needed packages
import 'package:datadome/datadome.dart';
import 'package:http/http.dart' as http;

//creating the DataDome client
DataDome client = DataDome('DATADOME_CLIENT_SIDE_KEY');

//performing a POST request
http.Response response = await client.post(url: 'https://example.com', 
																					 body: {'title': 'foo', 'body': 'bar', 'userId': '1'});

//using the response            
print('Response status: ${response.statusCode}');
print('Response headers: ${response.headers}');
print('Response body: ${response.body}');
            

How to test

📘

To test your integration, you need to activate the protection on your endpoints

Force a captcha display

❗️

Do not use the BLOCKUA User-Agent in production

To test your integration, add the header User-Agent with the value BLOCKUA to your request. This will hint the remote protection module to block the current request. The plugin will react to the blocked request (403 code) and display a challenge.

//importing needed packages
import 'package:datadome/datadome.dart';
import 'package:http/http.dart' as http;

//creating the DataDome client
DataDome client = DataDome('DATADOME_CLIENT_SIDE_KEY');

//performing a GET request with the BLOCKUA User-Agent header
http.Response response = await client.get(url: 'https://example.com', 
																					headers: {'User-Agent': 'BLOCKUA'});

//using the response            
print('Response status: ${response.statusCode}');
print('Response headers: ${response.headers}');
print('Response body: ${response.body}');