@dnode/request
v1.3.5
Published
[![dependencies | 6 | 60](https://img.shields.io/badge/dependencies-6%20|%2060-blue.svg)](DEPENDENCIES.md)
Downloads
27
Readme
Usage
Simplest usage
const Request = require('@dnode/request').Request;
const response = await new Request().get('http://google.de');
Set options for a request by a name
const RequestBuilder = require('@dnode/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('@dnode/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('@dnode/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'));