Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Because our API is REST based, the most important thing to do in any language is understand how to send HTTP Requests so you are able to call our system.  Many languages may have multiple ways to do this so we will show an example of how you can send requests in Java, Actionscript, curl, and your browser. 

 

Code Block
languagejava
titleJava - HTTP Request
collapsetrue
//set up url
String username = "sterling_archer@ikanow.com";
String hashedpassword = "WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U%3D"; //don't forget to URLEncode your arguments
String address = "http://infinite.ikanow.com/api/auth/login/" + username + "/" + hashedpassword;
        
//send request
URL url = new URL(address);
URLConnection urlConnection = url.openConnection();
((HttpURLConnection)urlConnection).setRequestMethod("GET");
                
//read back result
BufferedReader inStream = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder strBuilder = new StringBuilder();
String buffer;            
while ( (buffer = inStream.readLine()) != null )
{
    strBuilder.append(buffer);
}        
inStream.close();
        
//print out response json
System.out.println(strBuilder.toString());
Code Block
languageactionscript3
titleActionscript - HTTP Request
collapsetrue
protected function button_clickHandler( event:MouseEvent ):void
{
	//set up url
    var username:String = "sterling_archer@ikanow.com";
    var hashedpassword:String = "WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U%3D"; //don't forget to URLEncode your arguments
    var address:String = "http://infinite.ikanow.com/api/auth/login/" + username + "/" + hashedpassword;
                
	//send request
    var httpService:HTTPService = new HTTPService();
    httpService.addEventListener( ResultEvent.RESULT, httpResultHandler );
    httpService.addEventListener( FaultEvent.FAULT, httpFaultHandler );
    httpService.url = address;
    httpService.send();
}            
            
protected function httpFaultHandler( event:FaultEvent ):void
{
	Alert.show( "Http Request had an error: " + event.message );
}
            
protected function httpResultHandler( event:ResultEvent ):void
{
	//print out response json
	Alert.show( event.result.toString() );	
}
Code Block

...

titlecURL - HTTP Request
collapsetrue
curl http://infinite.ikanow.com/auth/login/sterling_archer@ikanow.com/WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U%3D
Code Block

...

titleWeb Browser - HTTP Request
collapsetrue
 1. In the url bar of your favorite web browser just type the url you want to navigate to and push go: http://infinite.ikanow.com/auth/login/sterling_archer@ikanow.com/WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U%3D

Once you have mastered how to send http requests, you can attempt to send requests to the API.  To login to the system you simply need to send an http request to http://infinite.ikanow.com/api/auth/login with username and password.  On a successful login, you will receive a cookie that will be active for 30 minutes from your last command.  This cookie will need to be passed back anytime you want to perform an API call that needs authentication. 

...