REST API Call using PHP

This code is very useful for crawling websites to fetch large number of information on a regular basis. To call a REST API, you need to use PHP curl.


<?php
$page = "";
if (isset($_GET['page'])) {
    $page = "&page=" . $_GET['page'];
} 

$url = "https://change_to_website_for_crawling/api";
$api_token = "change_to_your_api_key";

function curl_get_content($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('api_key' => $api_token));
    curl_setopt($curl, CURLOPT_URL, $url); //The URL to fetch. This can also be set when initializing a session with curl_init().
  
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); //The number of seconds to wait while trying to connect.

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
    curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
    curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //To stop cURL from verifying the peer's certificate.

   $contents = curl_exec($curl);
   curl_close($curl);
   return $contents;
}

$api_result = curl_get_content($url."/?api_key=".$api_token."&format=json".$page);
$obj = json_decode($api_result);
$result_array = objectToArray($obj);

foreach($result_array["joblisting"] as $data_key => $data){
   echo $data["name"] . "<br />";
}
?>

Next step of web developer

https://code.tutsplus.com/articles/the-11-phases-of-a-web-developers-career-as-illustrated-by-memes–net-30840

This is quite interesting. I am at the phase 10 of my career.

Sometimes I like doing web development, sometimes I also like doing database and back-end development.

Where to see Cherry Blossom in Taipei, Taiwan

It’s the Cherry Blossom season! If you’re in Taipei, you can visit Chiang Kai-Shek Memorial Hall to see the Japanese Flowering Cherry 大漁櫻 (Pale pink), Cerasus campanulata 緋寒櫻 (Pink), Azalea 杜鵑花, and whatnot. But if you are looking at Azalea 杜鵑花, you should visit National Taiwan University’s Azalea Festival instead.  Continue reading “Where to see Cherry Blossom in Taipei, Taiwan”

My favourite foods to eat in Tokyo, Japan

Japanese food is something I can’t have enough of; my all-time favourite food is none other than sushi and sashimi. I crave for them almost every one or two weeks. I can never get bored of Japanese food. Hence, Japan is one of my favourite countries to visit. If you are like me or have similar palate, I bet you will fall for Japanese food deeply as much as I do. ❤  Continue reading “My favourite foods to eat in Tokyo, Japan”

Tsukiji Fish Market in Tokyo, Japan

Tsukiji Inner Market vs Outer Market: Tsukiji Fish Market consists of 2 sections – Inner Market and Outer Market (see Tsukiji Fish Market map at http://japan-guide.com/e/e3021.html). Tuna auction and the famous restaurants are located in the Inner Market. Operations start as early as 5am and end in the early afternoon. On the other hand, crowds of Tsukiji Outer Market start later and there are shops selling ramen, sushi, light foods/snacks, groceries, kitchen tools, supplies etc. It is very crowded around Tsukiji. Do be on your guard so you don’t end up getting hit by a fish cart. Continue reading “Tsukiji Fish Market in Tokyo, Japan”

Guide to getting out of Seoul to Nami Island, Petite France, and Garden of Morning Calm in South Korea

Here’s my comprehensive guide on planning, transportation means and costs, and allocating time for each sightseeing. It was part of my itinerary and hopefully, it is useful to anyone looking for such guide. I’ve highlighted the train lines in their respective colours. Continue reading “Guide to getting out of Seoul to Nami Island, Petite France, and Garden of Morning Calm in South Korea”