How to use the get function from request
Find comprehensive JavaScript request.get code examples handpicked from public code repositorys.
request.get is a function that makes a GET HTTP request to a specified URL and returns the response as a callback function parameter.
GitHub: joaomirandas/whats2api
151 152 153 154 155 156 157 158 159 160
if(processData.status){ var download_options = { directory:F.path.private()+'audios/' , filename: U.GUID(10)+"-"+U.GUID(10)+".ogg" }; request.get(BODY['audio'], function (error, response, body) { if (!error && response.statusCode == 200) { data = "data:" + response.headers["content-type"] + ";base64," + Buffer.from(body).toString('base64'); WA_CLIENT.CONNECTION.sendFile(processData.chatId,data,'audio.ogg', (BODY['caption'] ? BODY['caption'] : "")); }
+ 21 other calls in file
41 42 43 44 45 46 47 48 49
url: url.format(specUrl), headers: { 'Accept': 'application/json', }, }; request.get(options, function(err, res, body) { if (err) { return cb(err); }
How does request.get work?
request.get is a method of the request library in Node.js, used for making HTTP requests to a specified URL using the GET method. When request.get is called, it constructs an HTTP GET request with the specified URL and sends it to the server. The response is then returned as a callback function parameter, which can be used to access the response body, headers, and status code. request.get supports a wide range of options, including custom headers, query parameters, and authentication, that can be passed as an optional options object. By default, request.get uses the Node.js http module to make the HTTP request, but it can also use the https module for secure requests. request.get is often used in Node.js applications to retrieve data from APIs or web services and process the response in some way, such as displaying it to the user, saving it to a database, or performing some computation based on the data.
GitHub: Paturages/chorus
17 18 19 20 21 22 23 24 25 26
new Promise(async (resolve, reject) => { const [, fileId] = url.match(/id=([^&]+)&?/) || url.match(/folders\/([^?]+)/) || []; if (!fileId) { Request.get(url, { encoding: null }, (err, res) => { if (err) return reject(err); // Bypass the download warning page if there's one if (res.body.toString('utf8', 0, 15) == '<!DOCTYPE html>') { return Drive.get(
GitHub: openaq/openaq-fetch
39 40 41 42 43 44 45 46 47 48 49
}); }); let getStations = function (baseUrl, link) { return function (done) { request.get({ headers: headers, url: link }, (err, res, body) => { if (err || res.statusCode !== 200) {
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const request = require("request"); request.get( "https://jsonplaceholder.typicode.com/todos/1", (error, response, body) => { if (error) { console.error(`Error: ${error}`); return; } console.log(`Response Status Code: ${response.statusCode}`); console.log(`Response Body: ${body}`); } );
In this example, we first import the request library. Then, we use request.get to make an HTTP GET request to the URL https://jsonplaceholder.typicode.com/todos/1. The second argument to request.get is a callback function that is called when the response is received. The callback function takes three parameters: error, response, and body. error will be set if there was an error during the request. response contains information about the response, such as the status code and headers. body contains the response body. In the callback function, we check if error is set, and if so, we print an error message and return. If error is not set, we print the status code and response body to the console. When we run the code, it will make an HTTP GET request to the specified URL and output the response status code and body to the console.
GitHub: ctide/fakeweb
2 3 4 5 6 7 8 9 10
const https = require('https'); const http = require('http'); const utils = require('./utils'); const url = require('url'); const oldRequestGet = request.get; const oldRequestPost = request.post; const oldHttpsRequest = https.request; const oldHttpRequest = http.request;
+ 19 other calls in file
59 60 61 62 63 64 65 66 67 68
after(function () { server.close(); }); beforeEach(function (done) { request.get(url, done); }); it('should attach a context object', function () { assert.deepEqual(context.value, testValue);
+ 39 other calls in file
40 41 42 43 44 45 46 47 48 49
default: benchmarkName = benchmarkVariant; } // fetch the timeline request.get( server + '/_apis/build/builds/' + buildId + '/timeline', { auth: auth, },
+ 11 other calls in file
30 31 32 33 34 35 36 37 38 39 40
} export const getReleaseInfo = async (projectId, appCode, moduleCode, env, bkTicket, bindInfo) => { const url = `${v3Config.URL_PREFIX}/bkapps/applications/${appCode}/modules/${moduleCode}/envs/${env}/released_state/?bk_app_code=${v3Config.APP_ID}&bk_app_secret=${encodeURI(v3Config.APP_SECRET)}&${global.AUTH_NAME}=${bkTicket}` return new Promise((resolve, reject) => { request.get(url, async function (error, response, body) { try { let res = body if (typeof body === 'string') { res = JSON.parse(body)
+ 2 other calls in file
2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
log.info('Group triggerTrackingGoal starting', { context: 'triggerTrackingGoal', params: req.body, group: group}); const options = { url: group.configuration.externalGoalTriggerUrl, qs: req.body }; request.get(options, (response, message) => { if ((response && response.errno) || (message && message.statusCode!==200)) { log.info('Group triggerTrackingGoal error', { context: 'triggerTrackingGoal', response: response, message: message, params: req.body, group: group}); res.sendStatus(500); } else {
GitHub: lplotni/pace
116 117 118 119 120 121 122 123 124 125
xit('should return participants matching filter', (done) => { participants.save(aParticipant) .then(participants.markPayed) .then(() => { request.get({url, qs}, (err, response) => { expect(response.statusCode).toBe(200); const result = JSON.parse(response.body); expect(result.draw).toBe('4711'); expect(result.recordsTotal).toBe(1);
+ 7 other calls in file
20 21 22 23 24 25 26 27 28 29
message: `Format must be one of ${JSON.stringify(VALID_FORMATS)}` }); } const url = `https://www.github.com/${user}`; request.get(url, (err, response, body) => { // Return error if request had an error if (err) return next(err); // Return 404 if user not found
GitHub: TripSit/factsheets
69 70 71 72 73 74 75 76 77 78
} var getCache = function(url,filename) { try { request.get(url, { 'json': true }, function(request, response, body) { if(!_.includes([200, 201], response.statusCode) || !_.isObject(body)) { return;
+ 3 other calls in file
GitHub: HPSoftware/truload
83 84 85 86 87 88 89 90 91 92
"?TENANTID=" + self.options.tenant_id + "&q=" var query = self.buildQuery(self.status) url += encodeURI(JSON.stringify(query)) r.get({url: url, json: true, jar: self.jar, proxy: self.options.proxy}, function(err, res, body) { if (handleHttpError("get time series", err, res, cba)) return for (metric in body) {
+ 17 other calls in file
106 107 108 109 110 111 112 113 114 115
AbbyyOcr.prototype._checkTask = function(options, task, callback) { var self = this; var url = self._getUrl(TASK_CHECK_PATH) + '?taskId=' + task.id; request.get({url: url, auth: self.appId + ':' + self.password}, parseTaskStatus(options, function(err, task) { if (err) { callback(err); return; }
+ 9 other calls in file
60 61 62 63 64 65 66 67 68 69
let uploadStream = s3Stream.upload({ Bucket: data.bucketName, Key: 'Imports/' + filePathExport }); request.get(url, setHeader(data.gcsToken)) .on('error', (error) => { electronWin.webContents.send(constants.IPC_EXPORT_TO_S3_FAILED, data.item); }).pipe(uploadStream); // Handle errors.
+ 7 other calls in file
34 35 36 37 38 39 40 41 42 43
}); }); describe('GET /api/catData', function () { xit('returns status 200', function (done) { request.get(base_url + '/api/catData', function (error, response, body) { expect(response.statusCode).toBe(200); done(); }); });
+ 39 other calls in file
95 96 97 98 99 100 101 102 103 104
const source = options.source; //const io = this.io; const configurl = options.configurl; if ( (typeof configurl !== 'undefined') && configurl) { request.get(configurl, this, function(error, response, body) { if (!error && response.statusCode === 200) { writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'downloading configuration from: ' + configurl); debug(body); writeConfig(source, body);
+ 11 other calls in file
34 35 36 37 38 39 40 41 42 43
.then((res) => { var latest_cid = res.data[res.data.length - 1]["cid"]; let dataUrl = `https://${latest_cid}.ipfs.dweb.link`; var httpclient = require("urllib").create(); return httpclient.request(dataUrl); // return request.get({ uri: dataUrl }); }) .then((response) => { console.log("res.data", response.data); let page_html = response.data.toString();
GitHub: LockerProject/Locker
97 98 99 100 101 102 103 104 105 106
function getConnectors(req, res) { var connectors = {}; // get all connectors from the registry var url = burrowBase + "/registry/_design/connectors/_view/Connectors"; request.get({uri:url, json:true}, function(err, ret, js){ if(js && js.rows && lutil.is('Array', js.rows)) js.rows.forEach(function(conn){ // if api key if(apiKeys[conn.id]) connectors[conn.id] = conn.value; // if no key required
+ 7 other calls in file
61 62 63 64 65 66 67 68 69 70
//proxy: 'http://127.0.0.1:8888', jar: getTokenJar, strictSSL: false }; let imgPath = path.resolve(__dirname, '../temp/', uuid.v4() + '.png'); request.get(getImgOption).on('error', reject).on('end', ()=> { logger.debug('Baidu imgcode page:' + imgPath); resolve({imgPath: imgPath, token: token}) }) .pipe(fs.createWriteStream(imgPath));
request.get is the most popular function in request (2246 examples)