How to use the get function from superagent

Find comprehensive JavaScript superagent.get code examples handpicked from public code repositorys.

superagent.get is a method used to send HTTP GET requests to a specified URL and retrieve data from the server.

142
143
144
145
146
147
148
149
150
151
  'beijing',
  'capetown',
]
function getWeatherOfRandomCity (request, response) {
  const city = CITIES[Math.floor(Math.random() * CITIES.length)]
  superagent.get(`wttr.in/${city}`)
    .end((err, res) => {
      if (err) {
        console.log('O snap')
        return response.status(500).send('There was an error getting the weather, try looking out the window')
fork icon106
star icon802
watch icon61

+ 3 other calls in file

18
19
20
21
22
23
24
25
26
27
var httpRequest = function (method, url, data, callback) {
    var ret;
    if (method == 'post') {
        ret = request.post(url).send(data);
    } else {
        ret = request.get(url).query(data);
    }
    var cookie = fm.getCookie();
    if (cookie)ret.set('Cookie', cookie);
    ret.set(header).timeout(10000).end(callback);
fork icon98
star icon355
watch icon37

How does superagent.get work?

superagent.get() is a method that initiates an HTTP GET request to the specified URL and returns a Request object which can be used to set headers, query parameters, and handle the response. The get() method is used to retrieve data from a server.

42
43
44
45
46
47
48
49
50
 * @param {String} path the relative path
 * @param {Object} data an object containing extra values 
 * @param {Function} callback the callback to invoke when the request completes 
 */
var tinderGet = function(path, data, callback) {
  request.get(TINDER_HOST + path)
    .set(getRequestHeaders())
    .end(callback);
};
fork icon61
star icon71
watch icon10

+ 3 other calls in file

237
238
239
240
241
242
243
244
245
246
247
  }
};


const main = async (timestamp = null) => {
  const stablecoins = (
    await superagent.get(
      'https://stablecoins.llama.fi/stablecoins?includePrices=true'
    )
  ).body.peggedAssets.map((s) => s.symbol.toLowerCase());
  if (!stablecoins.includes('eur')) stablecoins.push('eur');
fork icon373
star icon90
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
const superagent = require("superagent");

superagent
  .get("https://jsonplaceholder.typicode.com/todos/1")
  .then((response) => {
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });

This example sends a GET request to https://jsonplaceholder.typicode.com/todos/1 and logs the response body to the console.

170
171
172
173
174
175
176
177
178
179
}

for (var i = 0, len = _uniqueArr.length; len > i; i++) {
        let doc = _uniqueArr[i];
        if (/^\d+\.\d+\.\d+\.\d+$/.test(doc.ip) && doc.ip != '127.0.0.1' && doc.ip.toLowerCase() != 'localhost' && doc.ip.toLowerCase() != 'postman') {
                superagent.get(`http://api.map.baidu.com/location/ip`)
                .query({output: 'json'})
                .query({ak: _ak})
                .query({ip: doc.ip})
                .query({coor: 'bd09ll'})
fork icon26
star icon120
watch icon4

51
52
53
54
55
56
57
58
59
60

if (this.seen.indexOf(location) !== -1) return // already seen
this.seen.push(location)

// Request config url
var request = superagent.get(location);
request.buffer();
request.type('xml');
request.end(function(err, res) {
        if (err) return that.emit('error', err);
fork icon24
star icon158
watch icon22

206
207
208
209
210
211
212
213
214
```js
const superagent = require('superagent');

(async () => {
  try {
    const res = await superagent.get('https://jsonplaceholder.typicode.com/users');
    const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date';
    console.log('Status Code:', res.statusCode);
    console.log('Date in Response header:', headerDate);
fork icon9
star icon10
watch icon4

+ 5 other calls in file

110
111
112
113
114
115
116
117
118
119
}

query = queryArr.join("").replace(/\s+/,"%20")

// create a deferred obj
request.get(BASE_URL+query)
  // .set('User-Agent', USER_AGENT)
  .end(function(res) {
    if (res.statusCode != 200) {
      self.emit("error", CONNECTION_ERR)
fork icon7
star icon49
watch icon6

2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
*      request = superagent;
*
*  We can use the promise-like API, or pass callbacks:
*
*      request.get('/').end(function(res){});
*      request.get('/', function(res){});
*
*  Sending data can be chained:
*
*      request
fork icon26
star icon34
watch icon0

+ 27 other calls in file

62
63
64
65
66
67
68
69
70
71
key: 'translate',
value: function translate(queryObj) {
  var _this = this;

  return new Promise(function (resolve, reject) {
    request.get('https://openapi.baidu.com/public/2.0/bmt/translate').query({
      client_id: _this.apiKey,
      from: langsMap[queryObj.from] || 'auto',
      to: langsMap[queryObj.to] || 'auto',
      q: queryObj.text
fork icon79
star icon15
watch icon2

7
8
9
10
11
12
13
14
15
16
let dir = path.join(homedir(), '.sunphoton', 'solc')
let soljsonPath = path.join(dir, `soljson_v${compilerVersion}.js`)

await fs.ensureDir(path.join(dir))

let res = await req.get(`https://tron-us.github.io/tron-solc-bin/bin/soljson_v${compilerVersion}.js`)
  .responseType('blob')

if (res && res.body) {
  await fs.writeFile(soljsonPath, res.body)
fork icon4
star icon5
watch icon6

77
78
79
80
81
82
83
84
85
86
  await superagent
    .get(`${CLOUD_HTML_BASE_URL}/${filename}`)
    .set('Accept', 'text/html; charset=utf8');

export const triggerBadRequest = async () =>
  await superagent.get('http://superfake.biz/400');

export const bootstrapApp = async () => {
  await prefetchAboutData();
};
fork icon1
star icon10
watch icon4

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
61

// 搜索图书详情页
const searchDetail = async (link: string) => {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await superagent.get(link);
            const $ = cheerio.load(res.text);
            const content = $('.single-content');
            const imgSrc = content
                .find('.wp-caption.aligncenter')
fork icon3
star icon8
watch icon1

+ 3 other calls in file

23
24
25
26
27
28
29
30
31
32

```javascript
const superagent = require('superagent');
co(function*() {
  // Make an HTTP request to google's home page
  const google = (yield superagent.get('http://google.com')).text;
  const regexp = /google/i;
  // The number of times "Google" appears on google.com
  regexp.match(google).length;
});
fork icon3
star icon6
watch icon2

91
92
93
94
95
96
97
98
99
100
 * @param {string} link url
 * @returns {Promise} request promise
 */
getWithLoginInfo(link){
    return new Promise((resolve, reject)=>{
        superagent.get(link)
        .withCredentials()
        //.timeout({deadline: 6000})
        .set(this.headers)
        .then((res) => { resolve(res)})
fork icon1
star icon4
watch icon0

+ 3 other calls in file

5
6
7
8
9
10
11
12
13
14
const cfHostBase = 'mcf-np.threega.com'
const moment = require('moment')
const dateFmt = 'MMMM Do YYYY, h:mm:ss a'
const getRecentAppLogs = (guid) => {
  return getToken().then((token) => {
    return agent.get(`https://doppler.mcf-np.threega.com/apps/${guid}/recentlogs`)
                .responseType('blob')
                .set('Authorization', `Bearer ${token}`)
  })
}
fork icon4
star icon2
watch icon16

3
4
5
6
7
8
9
10
11
12

const baseUrl = 'https://m.mzitu.com/'

function initial() {
    return new Promise((resolve,reject)=>{
      superagent.get(baseUrl)
      .end((err, res) => {
        if (err) {
          reject(err);
        } else {
fork icon1
star icon2
watch icon2

+ 19 other calls in file

32
33
34
35
36
37
38
39
40
41

function getMovieByActor(name, callback){

  name = escape(name)
  console.log(name)
  request.get("http://api.themoviedb.org/3/search/person?api_key=da40aaeca884d8c9a9a4c088917c474c&query=" + name)
    .set('Accept', 'application/json')
    .end(function(err, res){
      if (err) {
        callback(err)
fork icon4
star icon0
watch icon2

77
78
79
80
81
82
83
84
85
86
87
88
}


function get(url) {
  debug('get', url);
  return new Promise((resolve, reject) => {
    var req = request.get(url);


    // We must call .buffer() for XML
    // requests to succeed. But for
    // some reason .buffer() isn't
fork icon3
star icon1
watch icon0

44
45
46
47
48
49
50
51
52
53
};

client.getAllApps = async () => {
    // https://api.steampowered.com/ISteamApps/GetAppList/v2/?key=xxx

    const search = await superagent.get('https://api.steampowered.com/ISteamApps/GetAppList/v2/')
                                    .query({
                                        key: process.env.STEAM_API_KEY
                                    });
    return search.body?.applist?.apps
fork icon2
star icon2
watch icon4

+ 44 other calls in file