Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Status Dependency Status devDependency Status

Installation

npm i --save drequest

Examples

Simplest usage

const Request = require('drequest').Request;

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

Set options for a request by a name

const RequestBuilder = require('drequest').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('drequest').RequestBuilder;

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

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

Define and use a class for more complex options

const RequestBuilder = require('drequest').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.request()
    .addOptions(new SearchOptions('how to use google search'))
    .send();

About

Building requests step by step in a modularized way

Resources

License

Releases

No releases published

Packages

No packages published