Giter Club home page Giter Club logo

request-slim's Introduction

REQUEST-SLIM

Extremely lite request lib without any dependencies ! ONLY FOR SIMPLE REQUEST FUNCTIONS !

Usage

For Node

require('request-slim')
import Request from 'requset-slim';

For Browser

require('request-slim/dist/request-broswer');
import Request from 'request-slim/dist/request-broswer';

Usage

const Request = require('request-slim');

// create a request object
const request = new Request({
    /**
     * common header fields.
     */
    headers: {
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
    },
    /**
     *  default response data type for all request
     */
    dataType: 'application/json',
    /**
     *  default request data type for all requst.
     */
    type: 'application/json',
    /**
     * common request paramas.
     */
    options: {
        proxy: () => 'http://127.0.0.1:8888',
        proxy: 'http://127.0.0.1:8888',
        proxy: {
            host: '127.0.0.1',
            protocol: 'http',
            port: 8888,
        },
    },
});

// GET request
await request.request({
    /**
     * method, default to 'GET'.
     */
    method: 'GET',
    url: 'https://www.google.com',
    /**
     * query params for GET request.
     */
    data: {
        a: 123,
    },
    headers: {
        'HOST': 'www.google.com',
    },
    /**
     * request content type
     */
    type: 'form' || 'json' || 'text' || 'application/json',
    /**
     * response content type
     */
    dataType: 'form' || 'json' || 'text' || 'application/json',
}).then(() => {/* ... */});


// POST request
request.request({
    method: 'POST',
    url: 'https://www.google.com',
    /**
     * body data for POST request.
     */
    data: {
        a: 123,
    },
});

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.