eden-rest
v0.0.32
Published
Eden Node JS General REST Methods
Readme
#Rest
DESCRIPTION
General
Installation
npm install eden-restUsage
var rest = require('eden-rest');Methods
setAuthentication
this setAuthentication( '[email protected]','yourpassword' );Sets authentication
Parameters
'[email protected]' - string (username)
'yourpassword' - string (password)
Returns
this
Example
Code
var username = '[email protected]';
var password = 'yourpassword';
rest().setAuthentication(username, password);
typeof result;Outputs
'object'setBody
this setBody( 'id=123&trim_user=false' );Sets the request body
Parameters
- 'id=123&trim_user=false' - string
Returns
this
Example
Code
rest().setBody('id=123&trim_user=false');
typeof response;Outputs
'string'setQueryBody
this setQueryBody( {id: '123', trim_user: false} );Sets the request body from an object to a string query
Parameters
- {id: '123', trim_user: false} - object
Returns
this
Example
Code
rest().setQueryBody({id: '123', trim_user: false});Outputs
'object'setJsonBody
this setJsonBody({id: '123', trim_user: false});Sets the request body from an object to JSON
Parameters
- {id: '123', trim_user: false} - object
Returns
this
Example
Code
rest().setJsonBody({id: '123', trim_user: false});
typeof response;Outputs
'object'setHeaders
this setHeaders('https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json', 'http://tinyurl.com/zhy5');Sets the headers hash
Parameters
string|object
mixed
Returns
this
Example
Code
var url = 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest().setHeaders(url , 'http://tinyurl.com/zhy5');Outputs
'string'setHost
this setHost('https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json');Sets the URL host
Parameters
- 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json' - string (url)
Returns
this
Example
Code
var url = 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json';
var result = rest().setHost(url);Outputs
'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json'setMethod
this setMethod('post');Sets the method IE GET, POST, PUT, DELETE
Parameters
- 'post' - string
Returns
this
Example
Code
var url = 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest()
.setUrl(url)
.setMethod('post');Outputs
'object'setPath
this setPath('https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json');Sets the url path
Parameters
- 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json' - string (url)
Returns
this
Example
Code
var url = 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest().setPath(url);Outputs
'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json'setPort
this setPort(3306);Sets the port
Parameters
- 3306 - int (port number)
Returns
this
Example
Code
var port = 3306;
rest().setPort(port);Outputs
'3306'setUrl
this setUrl('https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json');Disects URL
Parameters
- 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json' - string (url)
Returns
this
Example
Code
var url = 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest().setUrl(url);Outputs
'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json'useSSL
this useSSL('https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json');Use HTTPS
Parameters
Returns
this
Example
Code
var url = 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest().useSSL(url);
typeof response;Outputs
'string'getResponse
this getResponse(function, string);Sends off the request
Parameters
function(error, response) - function
'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json' - string
Returns
this
Example
Code
var url = 'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest().setUrl(url);
rest().getResponse(function(error, response));Outputs
'https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json'getJsonResponse
this getJsonResponse(Function, String);Sends off the request
Parameters
function
string
Returns
this
Example
Code
var url = 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest()
.setUrl(url)
.setMethod('post')
.setBody('id=123&trim_user=false')
.getJsonResponse(function(error, response,meta))Outputs
'object'getQueryResponse
this getQueryResponse(Function, String);Sends off the request
Parameters
function
string
Returns
this
Example
Code
var url = 'https://apiu.twitter.com/1.1/statuses/retweet/241259202004267009.json';
rest()
.setUrl(url)
.setMethod('post')
.setQueryBody({id: '123', trim_user: false})
.getQueryResponse(function(error, response));
typeof response;Outputs
'object'
