Sample Code
This topic gives resume parser code samples to get you start quickly.
Get more information on how you can quickly get started with RChilli APIs using Postman. This provides the technical information needed to access the RChilli services in flexible ways that will allow RChilli API to work seamlessly inside your application.
Sample Code - CSharp
Resume Parser API Sample Code CSharp 8.0.0, click download for the sample code.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
namespace SampleCode
{
class Program
{
//Set APIURL as rest api url for resume parsing provided by RChilli.
static String APIURL = "https://rest.rchilli.com/RChilliParser/Rchilli/parseResumeBinary";
//Set USERKEY as provided by RChilli.
static String USERKEY = "Your API UserKey";
static String VERSION = "8.0.0";
static void Main(string[] args)
{
//Set resume file path
String filePath = @"C:\resumefolder\resume.doc";
FileInfo file = new FileInfo(filePath);
byte[] DataFile = converttoBase64(file);
String subUserId="Your Company Name";
String request = "{\"filedata\":\"" + Convert.ToBase64String(DataFile)
+ "\",\"filename\":\"" + file.Name
+ "\",\"userkey\":\"" + USERKEY
+ "\",\"version\":\"" + VERSION
+ "\",\"subuserid\":\"" + subUserId
+ "\"}";
byte[] byteArray = Encoding.UTF8.GetBytes(request);
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(APIURL);
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
httpRequest.ContentLength = byteArray.Length;
httpRequest.Timeout = 300000;
Stream dataStream = httpRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8);
String response= streamReader.ReadToEnd();
Console.WriteLine(response);
Console.ReadKey();
}
public static byte[] converttoBase64(FileInfo fno)
{
try
{
Int64 numofbyte = fno.Length;
FileStream fs = new FileStream(fno.FullName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] DataFile = br.ReadBytes(Convert.ToInt32(numofbyte));
fs.Close();
fs.Dispose();
return DataFile;
}
catch (Exception ex)
{
}
byte[] error1 = new byte[1];
error1[0] = (byte)' ';
return error1;
}
}
}
Sample Code - Java
Resume Parser API Sample Code Java 8.0.0, click download for the sample code.
package RchilliApi;
import java.io.*;
import java.net.*;
public class program {
//Set APIURL as rest api url for resume parsing provided by RChilli.
static final String APIURL = "https://rest.rchilli.com/RChilliParser/Rchilli/parseResumeBinary";
//Set USERKEY as provided by RChilli.
static final String USERKEY = "Your API UserKey";
static final String VERSION = "8.0.0";
public static void main(String[] args) {
//Set resume file path
String filePath = "/home/resumefolder/resume.docx";
File resumeFile = new File(filePath);
try {
//Set Resume File Pat
String fileData = Base64.encodeFromFile(resumeFile.getAbsolutePath());
String subUserId = "Your Company Name";
String request = "{"
+ "\"filedata\":\"" + fileData + "\","
+ "\"filename\":\"" + resumeFile.getName() + "\","
+ "\"userkey\":\"" + USERKEY + "\","
+ "\"version\":\"" + VERSION + "\","
+ "\"subuserid\":\"" + subUserId + "\""
+ "}";
URL url = new URL(APIURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(request.getBytes());
os.flush();
BufferedReader br = null;
if (conn.getResponseCode() != 200) {
br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
} else {
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
}
String output;
StringBuilder sbOutput = new StringBuilder();
while ((output = br.readLine()) != null) {
sbOutput.append(output);
}
conn.disconnect();
br.close();
output = sbOutput.toString();
System.out.println(output);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Sample Code - NodeJs
Resume Parser API Sample Code NodeJs 8.0.0, click download for the sample code.
var https = require('https');
var fs = require('fs'),
// file data from file
FILE_DATA=base64_encode('SampleResume.docx')
/**
* HOW TO Make an HTTP Call - POST
*/
// do a POST request
// create the JSON object
function base64_encode(file) {
// read binary data
var binaryData = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(binaryData).toString('base64');
}
jsonRequest = JSON.stringify({
'filedata':FILE_DATA,
//filename
'filename':'SampleResume.docx'
,'userkey':'Your API UserKey'
,'version':'8.0.0'
,'subuserid':'Your Company Name'
});
// prepare the header
var postheaders = {
'Content-Type' : 'application/json',
'Content-Length' : Buffer.byteLength(jsonRequest, 'utf8')
};
// the post options
var optionspost = {
host : 'rest.rchilli.com',
port : 80,
path : '/RChilliParser/Rchilli/parseResumeBinary',
method : 'POST',
headers : postheaders
};
console.info('Options prepared:');
console.info(optionspost);
console.info('Do the POST call');
// do the POST call
var reqPost = https.request(optionspost, function(res) {
console.log("statusCode: ", res.statusCode);
// uncomment it for header details
// console.log("headers: ", res.headers);
res.on('data', function(d) {
console.info('POST result:\n');
process.stdout.write(d);
console.info('\n\nPOST completed');
});
});
// write the json data
reqPost.write(jsonObject);
reqPost.end();
reqPost.on('error', function(e) {
console.error(e);
});
Sample Code - PHP
Resume Parser API Sample Code PHP 8.0.0, click download for the sample code.
class RchilliService
{
//Your Api Link
$APIURL="https://rest.rchilli.com/RChilliParser/Rchilli/parseResumeBinary";
public function __construct()
{
}
public function resumeParseBinary($encode64,$type )
{
try
{
$encode64 = base64_encode($encode64);
$key='Your API UserKey';
$version = "8.0.0";
$subUserId = "Your Company Name";
$data = array(
"filedata" => $encode64,
"filename" => $type,
"userkey" => $key,
"version" => $version,
"subuserid" => $subUserId
);
$str_data = json_encode($data);
$ch = curl_init($APIURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $str_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($str_data))
);
$result = curl_exec($ch);
return $result;
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
Sample Code - Python
Resume Parser API Sample Code Python 8.0.0, click download for the sample code.
import base64
import requests
import json
APIURL="https://rest.rchilli.com/RChilliParser/Rchilli/parseResumeBinary"
USERKEY = 'Your API UserKey'
VERSION = '8.0.0'
subUserId = 'Your Company Name'
# file absolutepath
filePath='/home/resumefolder/SampleResume.docx'
fileName='SampleResume.docx'
# service url- provided by RChilli
with open(filePath, "rb") as filePath:
encoded_string = base64.b64encode(filePath.read())
data64 = encoded_string.decode('UTF-8')
headers = {'content-type': 'application/json'}
body = """{"filedata":\""""+data64+"""\","filename":\""""+ fileName+"""\","userkey":\""""+ USERKEY+"""\",\"version\":\""""+VERSION+"""\",\"subuserid\":\""""+subUserId+"""\"}"""
response = requests.post(APIURL,data=body,headers=headers)
resp =json.loads(response.text)
#please handle error too
Resume =resp["ResumeParserData"]
#read values from response
print (Resume["Name"]["FirstName"])
Sample Code - Ruby
Resume Parser API Sample Code Ruby 8.0.0, click download for the sample code.
require 'rubygems'
require 'net/http'
require 'rexml/document'
require 'base64'
require 'uri'
require 'json'
url = "https://rest.rchilli.com/RChilliParser/Rchilli/parseResumeBinary"
uri = URI.parse(url)
file_name = "SampleResume.docx"
userKey="Your API UserKey"
version="8.0.0"
subUserId="Your Company Name"
fileBuf = File.open(file_name,"rb") {|io| io.read}
base64Data=Base64.encode64(fileBuf)
String input = {"filedata"=>base64Data,"filename"=>file_name,"userkey"=>userKey, "version"=> version,"subuserid"=>subUserId};
headers = {'Content-Type' =>'application/json',
'Accept' => "application/json"}
http = Net::HTTP.new(uri.host,uri.port) # Creates a http object
#http.use_ssl = true # When using https
#http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.post(uri.path,input.to_json,headers)
puts response.code
puts response.body