npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reixs

v0.3.0

Published

The HTTP request library

Downloads

3

Readme

English | 简体中文
Reixs is a modern HTTP request library running in a browser environment that enables flexible and controllable HTTP request management.

Overview

Reixs works by predeclaring the callback content of an HTTP request and processing the server response in the form of a registration task. When the reixs-initiated request completes, the registered tasks are incrementally executed.

Asynchronous processing of network requests has always been a headache for developers. Reixs can effectively solve Callback Hell and other asynchronous processing problems by splitting the request and response. Unlike other modern HTTP request libraries, reixs is not dependent on promise implementations. Reixs can do more flexible operation on HTTP request through dynamic binding and unbinding request task.

Features

  • Make fetch from the browse
  • Intercept request and response
  • Transform request and response data
  • Automatic transforms for JSON data
  • Register and cancel response tasks
  • Request throttling operation

Installation

npm install reixs --save

The bottom layer of reixs USES the fetch api to send requests. If fetch is not supported, please manually introduce polyfill of fetch.

npm install fetch-polyfill --save

npm install node-fetch-polyfill --save

Start

import reixs from 'reixs'

// Create a reixs scheduler and register tasks
let scheduler = reixs('http://api...')
    .task(data => {
        console.log(`data:${data}`)
    })

// Send requests, default to GET requests
scheduler.request()

This is a simple example of a reixs request. reixs encourages the separation of requests and callbacks, allowing for better functional deconstruction.

The 'request API' takes the request data and the request type as parameters

scheduler.request(
    {
        id:12,
        name:"lili"
    },
    'get'
)

Instance methods

For convenience, dedicated methods are provided for all supported request types.

// Query String Parameters
scheduler.get()
// Path
scheduler.push()
// Request Plyload
scheduler.post()
// FormData
scheduler.form()

When using proprietary methods, there is no need to specify the request type.

Operation

Reixs USES chain call API design.

let scheduler = reixs('http://api...')
    // Sets the request header
    .setHeader({
        'Accept-Encoding':'gzip'
    })
    // Set the default request parameters and do not enable deep copy
    .setParams({id:12}, false)
    // Sets no cookies
    .setCookie(false)
    // Set 500ms throttling 
    .throttle(500)
    // Set 300ms debounce
    .debounce(300)

scheduler.get()

Lifecycle

Reixs provides the full Lifecycle for a single reques

let scheduler = reixs('http://api...')
    // When the 'request API' is invoked
    .prepare(() => {
        console.log('Request pending')
    })
    // When the HTTP request is sent
    .start(() => {
        console.log('Request start')
    })
    // End of HTTP request
    .end(() => {
        console.log('Request closed')
    })
    // Error time
    .error(error => {
        throw error
    })

scheduler.get()

Task

Bind multiple tasks.

let task1 = function(){
    console.log('task1')
}
let task2 = function(){
    console.log('task2')
}
let task3 = function(){
    console.log('task3')
}
let scheduler = reixs('http://api...')
    .task(task1)
    .task(task2)
    .task(task3)

scheduler.get()

cancel the task.

// Cancel task
scheduler.removeTask(tesk1)
// Cancel all tasks
scheduler.removeAllTask()

Note that the cancel task operation does not support chain calls.

Data Processing

let scheduler = reixs('http://api...')
    // Request interceptor before filtering
    .reqInterceptor(data => {
        if(data === 1){
            return false
        }
    })
    // Request filter
    .reqPipes( data => {
        return data + 1
    })
    // Request interceptor after filtering
    .reqInterceptor(data => {
        if(data === 3){
            return false
        }
    })
    // Response interceptor before filtering
    .resInterceptor(data => {
        if(!data){
            return false
        }
    })
    // Response filter
    .resPipes( data => {
        return data - 1
    })
    // Response interceptor after filtering
    .resInterceptor(data => {
        if(data <= 0){
            return false
        }
    })

scheduler.get(0)

Global Config

import reixs from 'reixs'

// Set global request headers
reixs.globalHeader = {
    'Accept-Encoding':'gzip'
}
// Global carry parameter when the request parameter is a {key:value} structure
reixs.globalParams = {
    id:12
}

// Global request filter
reixs.reqPipes(fn)
// Global response filter
reixs.resPipes(fn)
// Request interceptors before global filtering
reixs.beforeReq(fn)
// Request interceptors after global filtering
reixs.afterReq(fn)
// Response interceptors before global filtering
reixs.beforeRes(fn)
// Response interceptors after global filtering
reixs.afterRes(fn)

Scheduler replication

For scenarios where we need to reuse a scheduler configuration, we can use the copy function.

let scheduler = reixs('http://api...')
let newScheduler = reixs.copy(scheduler)

The new scheduler inherits all the properties of the original scheduler, and operations on the new scheduler do not apply to the original scheduler.

Scheduler Group

let scheduler1 = reixs('http://api1...')
let scheduler2 = reixs('http://api2...')

// The task is invoked after all request responses are complete
let allScheduler = reixs.all(scheduler1, scheduler2)
    .test((data1, data2) => {
        console.log(data1, data2)
    })

allScheduler.request()

// The first request to respond invokes the task
let raceScheduler = reixs.race(scheduler1, scheduler2)
    .test((data) => {
        console.log(data)
    })

raceScheduler.request()

// Requests are processed in tandem
let successionScheduler = reixs.succession(scheduler1, scheduler2)
    .test((data) => {
        console.log(data)
    })

successionScheduler.request()

The scheduler group passes through the scheduler's filters and interceptors within the group as it processes the data.

let scheduler1 = reixs('http://api1...')
    .resPipes(data => data + 1)

let scheduler2 = reixs('http://api2...')
    
// After requesting api1, the data is filtered as a parameter to the request api2.
let successionScheduler = reixs.succession(scheduler1, scheduler2)
    .test((data) => {
        console.log(data)
    })

The scheduler group inherits the life cycle of the reixs scheduler and the throttling operations

let allScheduler = reixs.all(scheduler1, scheduler2)
    // Set 500ms throttling
    .throttle(500)
    // Request sending starts
    .start(() => {
        console.log('Request start')
    })
    // Error time
    .error(error => {
        throw error
    })
    .test((data1, data2) => {
        console.log(data1, data2)
    })

allScheduler.request()

Because a scheduler group is itself a scheduler, it can be nested freely.

let scheduler1 = reixs('http://api1...')
let scheduler2 = reixs('http://api2...')

let raceScheduler = reixs.race(scheduler1, scheduler2)

let allScheduler = reixs.all(raceScheduler, scheduler2)

let successionScheduler = reixs.succession(allScheduler, raceScheduler)

Contributors

Thanks to everyone who contributed to the source code, comments, scripts, documentation, and test cases.