init

splunkjs.Http.init

Constructor for splunkjs.Http

Syntax

init: function(isSplunk)

Parameters

Name Type Description
isSplunk Boolean

Whether or not this is HTTP instance is for talking with splunkjs.

Return

splunkjs.Http. A splunkjs.Http instance

_buildResponse

splunkjs.Http._buildResponse

Construct a unified response

This function will generate a unified response given the parameters

Syntax

_buildResponse: function(error, response, data)

Parameters

Name Type Description
error Object

Error object if there was one for the request

response Object

The actual response object

data Object

The response data

Return

Object. A unified response object

parseJson

splunkjs.Http.parseJson

Client-specific JSON parsing logic

This function encapsulates the actual logic for parsing the JSON response.

Syntax

parseJson: function(json)

Parameters

Name Type Description
json String

JSON to parse

makeRequest

splunkjs.Http.makeRequest

Client-specific request logic

This function encapsulates the actual logic for performing a request, and is meant to be overriden by subclasses.

Syntax

makeRequest: function(url, message, callback)

Parameters

Name Type Description
url String

URL to request (already encoded)

message Object

Object with values for method, headers, timeout and encoded body

Callback Function

for when the request is complete: (err, response)

request

splunkjs.Http.request

Perform a request

This function sets up everything to handle the response from a request, but delegates the actual calling to the subclass using makeRequest.

Syntax

request: function(url, message, callback)

Parameters

Name Type Description
url String

URL to request (already encoded)

message Object

Object with values for method, headers, timeout and encoded body

Callback Function

for when the request is complete: (err, response)

del

splunkjs.Http.del

Perform a DELETE request

Syntax

del: function(url, headers, params, timeout, callback)

Parameters

Name Type Description
url String

URL to request

headers Object

Object of headers for this request

params Object

Query parameters for this request

timeout Number

Timeout (currently ignored)

callback Function

Callback for when the request is complete: (err, response)

post

splunkjs.Http.post

Perform a POST request

Syntax

post: function(url, headers, params, timeout, callback)

Parameters

Name Type Description
url String

URL to request

headers Object

Object of headers for this request

params Object

Body parameters for this request

timeout Number

Timeout (currently ignored)

callback Function

Callback for when the request is complete: (err, response)

get

splunkjs.Http.get

Perform a POST request

Syntax

get: function(url, headers, params, timeout, callback)

Parameters

Name Type Description
url String

URL to request

headers Object

Object of headers for this request

params Object

Body parameters for this request

timeout Number

Timeout (currently ignored)

callback Function

Callback for when the request is complete: (err, response)

encode

splunkjs.Http.encode

Helper function to encode a dictionary of values into a URL-encoded format.

Syntax

root.encode = function(params)

Parameters

Name Type Description
params Object

Parameters to URL-encode

Return

String. URL-encoded query string

Examples

 // should be a=1&b=2&b=3&b=4
 encode({a: 1, b: [2,3,4]})