Tag Archives: api

Test Your API by making HTTP requests from Hurl.it Software & Sites 07 JUN 2015

Needless to say, services, or web API endpoints, is a must in this day and age of software development, and as such I find myself writing more and more of these for my various systems. Invariably, this means testing them as well, which is precisely where tools allowing you to craft HTTP requests and target them at your API endpoints are so particularly useful.

One of these HTTP request generator tools that I recently stumbled upon thanks to a work colleague (thanks Rory!), is hurl.it, a free little tool brought to us by the guys who build their business on monitoring and measuring your API usage, aka Runscope.

Hurl.it is a simple one page site that allows you to enter a destination URL (with the option to follow redirects if necessary), add authentication and HTTP headers if desired, and of course throw in whatever parameters you need chucked in – before asking you nicely to prove that you are a human and then launching the request, displaying the resulting response in a nice display of headers and body.

Simple, but easy to use and works like a charm.

unicorn vomit hurl.it logo rainbow throw up

Related Link: https://www.hurl.it/ | reCAPTCHA

PHP and Google Charts: Using a POST request when a GET String is too Long CodeUnit 16 JUN 2010

Google Charts is an extremely stable and reliable web-based charting engine that is perfect for dropping into any project where you quickly want to produce some high quality graphs for your end user.

The default way to generate a Google Chart is to simple create a normal image tag and set its source to the Google API script with all the chart options passed along as a GET request string.

Of course, as we all know, there is a limit to the length of a GET string and so the question is raised once you start generating bigger graphs, how do you get around this particular limitation?

Well the answer of course lies in using a POST request instead, and thanks to PHP’s explicit support for POST requestes, this becomes as easy as pie! :)

Swiping the demo code straight from Google’s documentation because I’m too lazy to paste my own development example, you can see that the PHP script which handles the generation is nothing more than a file that pushes through the appropriate image content header (in this case a png) and then makes use of the classic fopen functionality (ensure that remote URL access is enabled on your server) to pull down the generated image from Google’s Chart API, specifically setting a POST stream context to handle the chart parameters stored in the previously created data array.

The final leg of work is then of course to simply reference your PHP script as the src of an image tag on the page you want the actual graph to appear.

PHP Chart Script:

  // Create some random text-encoded data for a line chart.
  header('content-type: image/png');
  $url = 'http://chart.apis.google.com/chart';
  $chd = 't:';
  for ($i = 0; $i < 150; ++$i) {
    $data = rand(0, 100000);
    $chd .= $data . ',';
  }
  $chd = substr($chd, 0, -1);

  // Add data, chart type, chart size, and scale to params.
  $chart = array(
    'cht' => 'lc',
    'chs' => '600x200',
    'chds' => '0,100000',
    'chd' => $chd);

  // Send the request, and print out the returned bytes.
  $context = stream_context_create(
    array('http' => array(
      'method' => 'POST',
      'content' => http_build_query($chart))));
  fpassthru(fopen($url, 'r', false, $context));

HTML Page to Display Chart:


Simple, but remarkably effective and thus clever! :P

Related Link: http://code.google.com/apis/chart/docs/post_requests.html