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.

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

Post View Counts WordPress plugin (Documentation)

The Post View Counts plugin is a simple tool for tracking and displaying the number of views for each post […]

December 30, 2022

How to create Laravel Flash Messages

Laravel flash messages are a convenient way to display one-time notifications to the user after a form submission or other […]

December 22, 2022

How to make Custom Artisan Command in Laravel

Custom Artisan commands are a useful feature of Laravel that allow you to define your own command-line commands for tasks […]

December 22, 2022

Digital Marketing Toolkit

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

Get Free Access Now