How to use the superagent.Request.prototype function in superagent

To help you get started, we’ve selected a few superagent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github acdlite / flummox-isomorphic-demo / src / shared / init.js View on Github external
/*
 * Polyfills
 */
// require('babel/runtime');
import 'babel/polyfill';

/*
 * Superagent promisification
 */
import { Request } from 'superagent';

Request.prototype.exec = function() {
  let req = this;

  return new Promise ((resolve, reject) => {
    req.end((error, res) => {
      if (error) return reject(error);
      resolve(res);
    });
  });
};
github lawrence0819 / neptune-front / src / api / shared.ts View on Github external
import * as Promise from 'bluebird';
import { Request, Response } from 'superagent';
import { ApiStreamResponse } from '../constants/interfaces';

const R = require('superagent').Request
const _end = Promise.promisify(R.prototype.end);

export const apiBaseUrl = '/api';

export interface Options {
  [name: string]: string;
}

export function end(request: Request): Promise {
  return _end.apply(request);
}

export function stream(request: Request): ApiStreamResponse {
  let response: ApiStreamResponse;
  request.on('progress', e => {
    if (response.onprogress) {
      const xhr = e.target;
github azproduction / node-mc / shared / request.js View on Github external
import request, {Request} from 'superagent';

Request.prototype.exec = function () {
    return new Promise((resolve, reject) => {
        this.end((error, res) => {
            if (error) {
                return reject(error);
            }
            resolve(res);
        });
    });
};

export default request;
github olegsmetanin / react_react-router_flummox_example / src / assets / js / apps / firstapp / utils / HttpRequest.js View on Github external
import { Request } from 'superagent';
import request from 'superagent';


Request.prototype.exec = function() {
  let req = this;

  return new Promise ((resolve, reject) => {
    req.end((error, res) => {
      if (error) return reject(error);
      resolve(res);
    });
  });
};

export default request;