var qs = require('qs'),
	apiUrl = 'http://localhost:3000',
	request = require('request-json'),
	client = request.newClient(apiUrl);
function checkResponse(err, apiRes, next){
    if(err) return next(err);

    if(apiRes && [500, 401, 404].indexOf(apiRes.statusCode) > -1){
        next(new Error(JSON.stringify(apiRes.body)));
        return false;
    }
    return true;
}
module.exports = {
	getBoards: function(_callback){
		var route = '/boards';

		client.get(route, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	getBoard: function(shortname, _callback){
		var route = '/board/';

		if(shortname){
			route += shortname;
		}

		client.get(route, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	getThread: function(thread, page, _callback){
		var route = '/thread/';

		if(thread){
			route += thread;
		}

		if(page){
			route += '/' + page;
		}

		client.get(route, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	getIndexThreads: function(board, page, _callback){
		var route = '/threads/';

		if(board){
			route += board;
		}else{
			route += 'all';
		}

		if(page){
			route += '/' + page;
		}

		client.get(route, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	getTotalThreads: function(board, _callback){
		var route = '/totalThreads/';

		if(board){
			route += board;
		}else{
			route += 'all';
		}

		client.get(route, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	newThread: function(params, _callback){
		var route = '/newThread';

		if(!params){
			params = {};
		}

		client.post(route, params, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	},
	newReply: function(params, _callback){
		var route = '/newReply';

		if(!params){
			params = {};
		}

		client.post(route, params, function(err, response, json){
			if(!checkResponse(err, response, _callback)) return;

			_callback(null, json);
		});
	}
};

@@ -125,16 +125,217 @@
 piUrl);%0A
+function makeRequest(method, url, params, _callback)%7B%0A%09client%5Bmethod%5D(url, params, function(err, response, json)%7B%0A%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09_callback(null, json);%0A%09%7D)%0A%7D%0A
 function
@@ -652,401 +652,213 @@
 %0A%0A%09%09
-client.get(route, function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D);%0A%09%7D,%0A%09getBoard: function(shortname, _callback)%7B%0A%09%09var route = '/board/';%0A%0A%09%09if(shortname)%7B%0A%09%09%09route += shortname;%0A%09%09%7D%0A%0A%09%09client.get(route, function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+makeRequest('get', route, null, _callback);%0A%09%7D,%0A%09getBoard: function(shortname, _callback)%7B%0A%09%09var route = '/board/';%0A%0A%09%09if(shortname)%7B%0A%09%09%09route += shortname;%0A%09%09%7D%0A%0A%09%09makeRequest('get', route, null, _callback
 );%0A%09
@@ -1020,143 +1020,49 @@
 %0A%0A%09%09
-client.get(route, function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+makeRequest('get', route, null, _callback
 );%0A%09
@@ -1256,143 +1256,49 @@
 %0A%0A%09%09
-client.get(route, function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+makeRequest('get', route, null, _callback
 );%0A%09
@@ -1450,143 +1450,49 @@
 %0A%0A%09%09
-client.get(route, function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+makeRequest('get', route, null, _callback
 );%0A%09
@@ -1598,36 +1598,44 @@
  %7B%7D;%0A%09%09%7D%0A%0A%09%09
-client.
+makeRequest('
 post
-(
+', 
 route, param
@@ -1641,125 +1641,17 @@
 ms, 
-function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+_callback
 );%0A%09
@@ -1763,20 +1763,28 @@
 %0A%0A%09%09
-client.
+makeRequest('
 post
-(
+', 
 rout
@@ -1798,125 +1798,17 @@
 ms, 
-function(err, response, json)%7B%0A%09%09%09if(!checkResponse(err, response, _callback)) return;%0A%0A%09%09%09_callback(null, json);%0A%09%09%7D
+_callback
 );%0A%09

Add makeRequest function in apiClient.js