Q.Utils Class
Different utilities
Item Index
Methods
Methods
_request
-
method -
uri -
[data=''] -
[query=null] -
[user_agent='Mozilla/5.0'] -
[header={}] -
[callback=null]
Issues an http request, and returns the response
Parameters:
-
methodStringThe http method to use
-
uriString | ArrayThe URL to request This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI
-
[data='']Object | String optionalThe associative array of data to add to query
-
[query=null]Object optionalThe associative array of data to post
-
[user_agent='Mozilla/5.0']String optionalThe user-agent string to send. Defaults to Mozilla.
-
[header={}]Object optionalOptional associative array of headers to replace the entire header
-
[callback=null]Function optionalCallback receives error and result string as arguments
get
-
url -
[data=''] -
[user_agent='Mozilla/5.0'] -
[header={}] -
[callback=null]
Issues a GET request, and returns the response
Parameters:
-
urlString | ArrayThe URL to get from This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI
-
[data='']Object | String optionalThe associative array of data or string to add to query
-
[user_agent='Mozilla/5.0']String optionalThe user-agent string to send. Defaults to Mozilla.
-
[header={}]Object optionalOptional associative array of headers to replace the entire header
-
[callback=null]Function optionalCallback receives error and result string as arguments
post
-
url -
[data=''] -
[query=null] -
[user_agent='Mozilla/5.0'] -
[header={}] -
[callback=null]
Issues a POST request, and returns the response
Parameters:
-
urlString | ArrayThe URL to post to This can also be an array of [url, ip] to send the request to a particular IP, while retaining the hostname and request URI
-
[data='']Object | String optionalThe associative array of data or string to add to query
-
[query=null]Array optionalThe associative array of data to post
-
[user_agent='Mozilla/5.0']String optionalThe user-agent string to send. Defaults to Mozilla.
-
[header={}]Object optionalOptional associative array of headers to replace the entire header
-
[callback=null]Function optionalCallback receives error and result string as arguments
preparePath
-
filename -
callback
Create folder for filename is it does not exists Folder is created with 'world' access rights with 'Q/internal/umask' config value applied as umask
queryExternal
-
handler -
[data={}] -
[url=null] -
[callback=null]
Queries a server externally to the specified handler. Expects json array with either ['slots']['data'] or ['error'] fields filled
Parameters:
queryInternal
-
handler -
[data={}] -
[url=null] -
[callback=null]
Sends a query to Node.js internal server and gets the response This method shall make communications behind firewal
Parameters:
sendToNode
-
data -
[url=null]
Sends internal message to Node.js
splitId
-
id -
[lengths=3] -
[delimiter=path.sep] -
[internalDelimiter='/']
Used to split ids into one or more segments, in order to store millions of files under a directory, without running into limits of various filesystems on the number of files in a directory. Consider using Amazon S3 or another service for uploading files in production.
Parameters:
-
idStringthe id to split
-
[lengths=3]Integer optionalthe lengths of each segment (the last one can be smaller)
-
[delimiter=path.sep]String optionalthe delimiter to put between segments
-
[internalDelimiter='/']String optionalthe internal delimiter, if it is set then only the last part is split, and instances of internalDelimiter are replaced by delimiter
Returns:
the segments, delimited by the delimiter
validate
()
express server middleware validate signature of internal request