How to use request-promise-native - 10 common examples

To help you get started, we’ve selected a few request-promise-native 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 actionhero / actionhero / __tests__ / servers / web / routes / routes.ts View on Github external
test("regexp matches will provide proper variables", async () => {
      const body = await request.post(url + "/api/login/123").then(toJson);
      expect(body.requesterInformation.receivedParams.action).toEqual("login");
      expect(body.requesterInformation.receivedParams.userID).toEqual("123");

      const bodyAgain = await request
        .post(url + "/api/login/admin")
        .then(toJson);
      expect(bodyAgain.requesterInformation.receivedParams.action).toEqual(
        "login"
      );
      expect(bodyAgain.requesterInformation.receivedParams.userID).toEqual(
        "admin"
      );
    });
github actionhero / actionhero / __tests__ / integration / sendBuffer.ts View on Github external
test("Server should sendBuffer", async () => {
    const body = await request.get(url + "/api/sendBufferTest");
    expect(body).toEqual("Example of data buffer");
  });
github actionhero / actionhero / __tests__ / servers / web / routes / routes.ts View on Github external
test("returns application/json when the mime type cannot be determined for an action", async () => {
      const response = await request.get(
        url + "/api/mimeTestAction/thing.bogus",
        { resolveWithFullResponse: true }
      );
      expect(response.headers["content-type"]).toMatch(/json/);
      const body = JSON.parse(response.body);
      expect(body.matchedRoute.path).toEqual("/mimeTestAction/:key");
      expect(body.matchedRoute.action).toEqual("mimeTestAction");
    });
github actionhero / actionhero / __tests__ / core / staticFile / staticFile.ts View on Github external
test("should send back the cache-control header", async () => {
      const response = await request.get(url + "/simple.html", {
        resolveWithFullResponse: true
      });
      expect(response.statusCode).toEqual(200);
      expect(response.headers["cache-control"]).toBeTruthy();
    });
github actionhero / actionhero / __tests__ / integration / sendBuffer.js View on Github external
test('Server should sendBuffer', async () => {
    const body = await request.get(url + '/api/sendBufferTest')
    expect(body).toEqual('Example of data buffer')
  })
github Azure / autorest.testserver / legacy / coverage / github.js View on Github external
constructor(githubRepo, githubTokenOfCI) {
    this.githubRepo = githubRepo;
    this.request = req.defaults({
      headers: {
        "User-Agent": "AutoRest CI",
        "Authorization": "token " + githubTokenOfCI
      }
    });
  }
github spring-cloud / spring-cloud-dataflow-ui / ui / protractor-docker-plugin / index.js View on Github external
downloadFile(url, destinationFilePath) {
        console.log('Start downloading file from ' + url);
        const requestPromiseCall = requestPromise.get(url, { json: false }, (error, response, body) => {
            console.log('content-type:', response.headers['content-type']);
            console.log('content-length:', response.headers['content-length']);
            if (response.statusCode < 200 || response.statusCode > 299) {
                throw new Error('Failed to load page, status code: ' + response.statusCode);
            }
            return body;
        }).then(body => {
            const buffer = Buffer.from(body, 'utf8');
            fs.writeFileSync(destinationFilePath, buffer);
            console.log('File downloaded!');
        });
        return requestPromiseCall;
    }
    sleep(ms) {
github tabeyti / jenkins-jack / src / jenkinsService.ts View on Github external
public async get(endpoint: string) {
        let url = `${this._jenkinsUri}/${endpoint}`;
        return request.get(url).catch(err => {
            console.log(err);
            vscode.window.showWarningMessage(this._cantConnectMessage);
            return undefined;
        });
    }
github leanix / leanix-reporting-cli / src / api-token-resolver.ts View on Github external
public static getAccessToken(host: string, apiToken: string) {
  const base64ApiToken = new Buffer('apitoken:' + apiToken).toString('base64');
  const options = {
    url: host + '/services/mtm/v1/oauth2/token',
    headers: { 'Authorization': 'Basic ' + base64ApiToken },
    form: { grant_type: 'client_credentials' }
  };

  return rp.post(options)
    .then(response => JSON.parse(response)['access_token']);
}
github looker / actions / src / actions / mparticle / mparticle_transaction.ts View on Github external
async sendChunk(rows: Hub.JsonDetail.Row[], mapping: any) {
    const chunk = rows.slice(0)
    const body: MparticleBulkEvent[] = []
    chunk.forEach((row: Hub.JsonDetail.Row) => {
      const eventEntry = this.createEvent(row, mapping)
      body.push(eventEntry)
    })
    const options = this.postOptions(body)
    await httpRequest.post(options).promise().catch((e: any) => {
      this.errors.push(`${e.statusCode} - ${mparticleErrorCodes[e.statusCode]}`)
    })
  }

request-promise-native

The simplified HTTP request client 'request' with Promise support. Powered by native ES6 promises.

ISC
Latest version published 4 years ago

Package Health Score

49 / 100
Full package analysis