Reqman is a tool that can quickly help back-end engineers with api testing, as well as a nodejs-based crawler tool.
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 8.0 or higher is required.
Installation is done using the
npm install
command:
$ npm install reqman
// Using Node.js `require()`
const Reqman = require('reqman');
// Using ES6 imports
import Reqman from 'reqman';
- ✔︎ Chained API
- ✔︎ Out of the box
- ✔︎ Crawler, can simulate requests
- ✔︎ Suitable for complex and strong coupling scenarios
- ✔︎ Powerful request library request based on nodejs
Reqman is designed to be like request and is the easiest way to make http calls. It supports https, to follow redirection by default.
All you have to do is write an anonymous function in the parameters of the push
method that returns a object
and return your request parameters.
Click here to view this example source code
//Importing Reqman, remember to capitalize the first letter because Reqman is a class.
const Reqman = require('reqman');
//new Reqman,and then the parameter is passed in a base address.
const req = new Reqman({
baseUrl: "https://github.com"
});
//For example, you can use reqman to grab the github address of this project, like this:
req
.push(function () {
return {
method: "GET",
url: `/lisniuse/reqman`
}
})
.done();
If you specify the showInfo parameter as false, the results will not be printed to the screen, like this:
req
.push(function () {
return {
method: "GET",
url: `/lisniuse/reqman`,
showInfo: false
}
})
.done();
In the chained API, the result of the first request is used as the argument to the second request. like this:
const Reqman = require('reqman');
const req = new Reqman({
baseUrl: "http://127.0.0.1:3000"
});
//Define account password
const user = {
username: "admin",
password: "admin"
}
req
//Request a login api
.push(function () {
return {
method: "POST",
url: `/api/login`,
data: user, //Pass in the user object just defined to data
complete: function (selfElement) { //Return the requestElement object of the queue
let response = selfElement.result.response;
let body = JSON.parse(response.body);
//Note: It is recommended not to hang public variables directly on the reqman instance, which may override the requman properties and methods. Reqman provides a store object to store the public variables that need to be stored during the request process.
this.store.userToken = body.data.token; //Get the user token
}
}
})
//Then we update the user's information with the token obtained after login.
.push(function () {
return {
method: "POST",
url: `/api/user/updateInfo`,
headers: {
'Authorization': this.store.userToken //The variables in the store can be directly used in subsequent requests.
},
data: {
nickname: "jack ma" //Update nickname jack ma
}
}
})
.done()//just do it.
'use strict'
const req = new Reqman({
baseUrl: "http://127.0.0.1:3000",
output: "./request-result.txt", //Append the result returned after the request to the specified file path at the same time.
specList: {
type: 'valid', //Parameters: invalid or valid. Define valid or invalid requests.
list: ['bob'] //Let the request named bob be valid and the rest of the requests invalid. If type is invalid, the opposite is true.
}
});
req.
//Define a request named bob, and the prevElement parameter represents the requestElement object of the previous request.
push('bob', function (prevElement) {
return {
method: "POST",
url: `/?name=bob`,
headers: { //With custom headers
'content-type': 'application/octet-stream'
},
complete: function (selfElement) { //Callback function after request
}
}
})
//Define a request named jack, and the prevElement parameter represents the requestElement object of the previous request.
.push('jack', function (prevElement) {
return {
baseUrl: 'http://127.0.0.1:4000', //Customize the base address for this request
output: "./jack-result.txt", //Customize the output file path for this request
method: "GET",
url: `/`,
data: {
name: 'jack'
},
showInfo: false, //Do not print the returned body information
complete: function (selfElement) { //Callback function after request
//do something...
}
}
})
.done(function () {
//exit the program
process.exit(1);
})
More examples in the projects folder of the project, you can run this command directly:
node getHelloworld.js
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
The MIT License (MIT)
Copyright (c) 2015-present ZhiBing <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.