How to work with Rapidapi using PHP CURL

I used to develop API and share it with RapidAPI. and get messages from people who like my API but they don’t know how to integrate the API with their website. So in this post, I will tell you how you can integrate API from Rapidapi into your website.

We mostly use the CURL method to send a GET request. I will explain how to create a CURL request with PHP and how to get data from RapidAPI.

So I took my Google Keyword Research API as an Example  

<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://google-keyword-research.p.rapidapi.com/keyword?keyword=email%20marketing&country=us",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "X-RapidAPI-Host: google-keyword-research.p.rapidapi.com",
        "X-RapidAPI-Key: xxxxxxxxxx- REPLACE YOUR API KEY HERE-xxxxxxxxx"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

So if you want to know how to make a small app with rapid API .. that’s a topic for another blog

Hope this help you.

Ajith Jojo Joseph

Hire Me for Freelancing $30/Hour ,
Contact via email : [email protected]

Share with your friends:

Comments are closed.

Drag and Drop with Swapy and PHP

Hello , You might had issues with drag and drop options in your dashboard. here i found a new javascript […]

September 17, 2024

How To Generate A PDF from HTML in Laravel 11

Hello , I was trying to generate a PDF payment receipt for my SAAS application and when i search for […]

June 22, 2024

How to get the next value of an array and loop it in the array in PHP

Do you know How to get the next value of an array and loop it in the array in PHP […]

July 28, 2023

New Open Source CRM for project Management and Invoicing

I’m excited to announce the launch of my new open source project: Gmax CRM. an invoicing and project management tool […]

December 31, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now