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.

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

How to get data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

Export html table to excel, pdf, csv format using Datatable

Do you know how to export html table to excel, pdf, CSV, or excel format using Datatable? If you don’t […]

August 4, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Instagram Hashtag API PHP and JavaScript Integration with RapidAPI

Do you know how to integrate Instagram Hashtag API with your website? In this tutorial, I will show you how […]

August 2, 2022

Digital Marketing Toolkit

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

Get Free Access Now