nl_tokens: Form and send request to API service
pl_tokens: function sendRequest ( path , method , data , useToken , callback ) { var headers = { } headers [ 'Content-Type' ] = 'application/json' ; headers [ 'Content-Length' ] = Buffer . byteLength ( JSON . stringify ( data ) ) ; if ( useToken && TOKEN . length ) { headers [ 'Authorization' ] = 'Bearer ' + TOKEN ; } if ( method === undefined ) { method = 'POST' ; } if ( useToken === undefined ) { useToken = false ; } var options = { //uri: API_URL, path : '/' + path , port : 443 , hostname : API_URL , method : method , headers : headers , } ; var req = https . request ( options , function ( response ) { var str = '' ; <mask> . on ( 'data' , function ( chunk ) { if ( response . statusCode == 401 ) { getToken ( ) ; sendRequest ( path , method , data , true , callback ) ; } else { str += chunk ; } } ) ; response . on ( 'end' , function ( ) { if ( response . statusCode != 401 ) { try { var answer = JSON . parse ( str ) ; } catch ( ex ) { var answer = returnError ( ) ; } callback ( answer ) ; } } ) ; } ) ; req . write ( JSON . stringify ( data ) ) ; req . end ( ) ; }