node.js - PHP to NodeJS REST API -
i'm working on converting made php utility nodejs code takes longer execute appropriate in php (causing time outs, etc.).
part of utility has connect rest api of ipboard forum software. in php so:
$data = array( "hidden" => "0", "sortdir" => "desc" ); $curl = curl_init( "http://pw-phoenix.com/forum/api/index.php?/forums/topics/". $intid . "&" . http_build_query($data) ); curl_setopt_array( $curl, array( curlopt_returntransfer => true, curlopt_httpauth => curlauth_basic, curlopt_userpwd => "---api key---", ) ); $lstresponse = json_decode( curl_exec( $curl ) ); return $lstresponse->results[0]->date;
now trying turn nodejs. found npm package "request" (https://github.com/request/request) , attempting use that. unfortunately, knowledge of apis , authentification limited cannot figure out equivalent of above authentification in nodejs , how pass api key / userpwd. please explain how done, or @ least direct me in correct direction. many thanks.
update
var request = require('request'); request.post('http://pw-phoenix.com/forum/api/index.php?/core/hello', { 'auth': { 'user': 'api key' } }, function(response){ console.log(response); });
i have tried suggested in comments, "null" displayed in console.
Comments
Post a Comment