Examples

Here are some basic examples for making get request to our restful api using different programming languages.

PHP

 
$url = "https://parsebot.com/api/v1/extract?key=[API_KEY]&tool=[TOOL]&url=[URL]";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);

if ($curl_response === false) {
    $info = curl_getinfo($curl);
    curl_close($curl);
    die("error occured during curl exec. Additioanal info: " . var_export($info));
}

curl_close($curl);

$decoded = json_decode($curl_response);

if (isset($decoded->response->status) && $decoded->response->status == "ERROR") {
    die("error occured: " . $decoded->response->errormessage);
}

var_export($decoded->response);

Node.js

 
var http = require("http");
    url = "https://parsebot.com/api/v1/extract?key=[API_KEY]&tool=[TOOL]&url=[URL]";

// get is a simple wrapper for request()
// which sets the http method to GET
var request = http.get(url, function (response) {
    // data is streamed in chunks from the server
    // so we have to handle the "data" event    
    var buffer = "", 
        data,
        route;

    response.on("data", function (chunk) {
        buffer += chunk;
    }); 

    response.on("end", function (err) {
        // finished transferring data
        // dump the raw data
        console.log(buffer);
        console.log("\n");
        data = JSON.parse(buffer);
        route = data.routes[0];
    }); 
}); 

Python

 
import urllib2

url = "https://parsebot.com/api/v1/extract?key=[API_KEY]&tool=[TOOL]&url=[URL]"

try:
	data = urllib2.urlopen(url).read()
	
except urllib2.HTTPError, e:
	print "HTTP error: %d" % e.code
	
except urllib2.URLError, e:
	print "Network error: %s" % e.reason.args[1]

Java

 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class Test {
 public static void main(String[] args) throws ClientProtocolException, IOException {
  HttpClient client = new DefaultHttpClient();
  HttpGet request = new HttpGet("https://parsebot.com/api/v1/extract?key=[API_KEY]&tool=[TOOL]&url=[URL]");
  
  HttpResponse response = client.execute(request);
  BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
  
  String line = "";
  while ((line = rd.readLine()) != null) {
    System.out.println(line);
  }
  
 }
}

Rails

 
require "net/http"
require "uri"

url = "https://parsebot.com/api/v1/extract?key=[API_KEY]&tool=[TOOL]&url=[URL]" 
uri = URI.parse(url)

Net::HTTP.get(uri) # GET request
# => "Here is some data."