Code Monkey home page Code Monkey logo

reqman's Introduction

English | 简体中文

Reqman

Reqman is a tool that can quickly help back-end engineers with api testing, as well as a nodejs-based crawler tool.

Financial Contributors on Open Collective NPM version

npm

Installation

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

Importing

// Using Node.js `require()`
const Reqman = require('reqman');

// Using ES6 imports
import Reqman from 'reqman';

Features

  • ✔︎ Chained API
  • ✔︎ Out of the box
  • ✔︎ Crawler, can simulate requests
  • ✔︎ Suitable for complex and strong coupling scenarios
  • ✔︎ Powerful request library request based on nodejs

Super simple to use

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.

Example 1: a single request

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();
  

Example 2: Chained API

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.

Example 3: Example of a complete representation of reqman's api and features

'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

More examples in the projects folder of the project, you can run this command directly:

node getHelloworld.js

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

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.

back to top

reqman's People

Contributors

lisniuse avatar monkeywithacupcake avatar zhangpaner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

reqman's Issues

reqman and reqman

HI,

It's completly mad ... I'm the author of reqman (https://github.com/manatlan/reqman)... a python command line tool, which do the same thing that your reqman. Except that it's based on yaml conf, and let you add tests controls (in yaml too). We share the same name, for the same thing ... it's mad ;-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.