@maxdome/request

1.3.4 • Public • Published

Usage

Simplest usage

const Request = require('@maxdome/request').Request;

const response = await new Request().get('http://google.de');

Set options for a request by a name

const RequestBuilder = require('@maxdome/request').RequestBuilder;

const requestBuilder = new RequestBuilder().setOptions('google', {
  url: 'http://google.de',
});

const response = await RequestBuilder.request('google').send();

Set options for all requests

const RequestBuilder = require('@maxdome/request').RequestBuilder;

const google = new RequestBuilder({
  url: 'http://google.de',
});

const response = await google.send();

Define and use a class for more complex options

const RequestBuilder = require('@maxdome/request').RequestBuilder;

const google = new RequestBuilder({
  url: 'http://google.de',
});

class SearchOptions {
  constructor(q) {
    this.q = q;
  }

  toRequestOptions() {
    return {
      url: {
        path: '/search',
        query: {
          q: this.q,
        },
      },
    };
  }
}

const response = await google
  .send(new SearchOptions('how to use google search'));

Readme

Keywords

none

Package Sidebar

Install

npm i @maxdome/request

Weekly Downloads

9

Version

1.3.4

License

none

Unpacked Size

12.5 kB

Total Files

8

Last publish

Collaborators

  • dragonnodejs
  • sharaal
  • fabsrc
  • markusz
  • mxdbv
  • csaba.lorincz
  • goexrock
  • dimified