Request Group
Request Group is a module for primarily Node.js environments and written in TypeScript. The entire purpose is to handle batch request of multiple kinds in a friendly and agnostic way. Included in this module are two basic classes called FileRequest and WebRequest to get the ball rolling in your project. These class's are only basic and may not satisfy all your needs. If you are looking to expand or develop your own request type it would be wise to start by extending the BaseRequest or BaseWebRequest. If you want to go deeper you can implement the Request interface entirely on your own. This module will of course work in a regular Node.js enviorment if that is your preference, but all examples and the preferred way to use this module is to use it with TypeScript. All *.ds.ts files are included when building
Installing
npm install request-group
Building
git clone https://github.com/GabrieleNunez/request-group.gitcd request-groupnpm installnpm run build
Creating a request-group
Fortunately creating a request-group is extremely simple and straight forward. If you are using TypeScript then RequestGroup only requires one type supplied and two parameters.
; // if you dont supply the queue size then the default is 4; // if you don't supply the queue interval then the default is 2500 or 2.5 seconds// the queue interval is given in millseconds since we use setTimeout; // create a new Request Group with a page engine type of string// the page engine is simply the output of the Request. This could be a class or a primitive.// For example if we are using Cheerio this **should** be RequestGroup<CheerioStatic>// If we are using puppeteer this **should** be RequestGroup<puppeteer.Page>; // OR you can also create a Request Group by using request.createManager(...) like so;; // both ways will work just fine and give you a Request Group// if you want to hook into the request group and find out ASAP when a request is completed// hook in a callback that way we can read and manipulate the page datarequestGroup.setRequestComplete; // after you create your Request Group just queue up the requestfoo.queuewebRequest; // when you are ready to run the queuefoo.run.then; /** * If you wanted to use await * await foo.run(); * console.log('Queue completed');*/
The PageEngine Type explained
RequestGroup<PageEngine>
The PageEngine is the output you are expecting from the request to return.
If you are using the built in request classes then the output is always going to be string.
To use Puppeteer and Cheerio as examples, if you wanted to create request to extend and return the output of those then the PageEngine **should** be puppeteer.Page or CheerioStatic respectively
How to use ( Extending )
Extending BaseWebRequest and using Cheerio as a page engine
cheerio_request.ts
// File: cheerio_request.ts ;;;;; ;
index.ts
// index.ts;; // demonstrate using cheerio for requestcheerioExample.then;
How to use (Built in File)
index.ts
; // demonstrate files using the included file requestfileExample.then;
Found a problem? Have a suggestion? Want a feature?
I am looking to colloborate more with other developers. All issues will be addresses ASAP and pull request's welcomed. Let's make something great
Development Dependencies
- @types/node ^12.0.10
- @types/request ^2.48.1
- @typescript-eslint/eslint-plugin ^ 1.11.0
- @typescript-eslint/parser ^ 1.11.1
- eslint ^6.0.1
- eslint-config-prettier ^ 6.0.0
- eslint-plugin-prettier ^ 3.1.0
- prettier ^ 1.18.2
- ts-node ^ 8.3.0
- typescript ^ 3.5.2
Library Dependencies
- moment ^ 2.24.0
- request ^ 2.88.0
Keywords
request scraping manager http file utility browser async asynchronous web eslint typescript prettier moment batch group
ヾ(-_- )ゞ
〈( ^.^)ノ
ƪ(ƪ꒪ৱ৹)ᵒʰ˵˵