I have a drupal 8 website and have a lot of integrations(using curl) in custom modules.
The URLs of these APIs and its parameters need to be configurable by an admin panel.
What is the best way to do that? Building a custom table and a custom form to save it or is there a specific module or create an entity type in admin configuration?
Here is my code:
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "**https://test?parameter1=test¶meter2=test"**,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"accept: application/json",
**"Authorization: Basic XXX"**
],
]);
You should create a Configuration Form to enter config values, and then
Configuration API
will save those values inconfig
table.When need to retrieve config values you can use: