New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

http-conn

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-conn

Small lib HTTP client for the browser, Promise based and cancelable.

latest
Source
npmnpm
Version
1.0.9
Version published
Maintainers
1
Created
Source

http-conn

Small lib HTTP client for the browser, Promise based and cancelable.

Install

npm install http-conn

Usage

import HttpConnector from 'http-conn'

const http = new HttpConnector({ 
    // [optional] set default timeout of request, in milliseconds
    timeout: 5000,

    // [optional] set default headers
    headers: {},

    // [optional] middleware from request
    onRequest(config) {
        config.headers.Authorization = 'mytoken'
    },

    // [optional] middleware from response
    onResponse(response) {
        let newResponse = {
            ...response,
            outher: true
        }

        return newResponse
    },

    // [optional] middleware from error
    onError(error) {
        console.log(error)
    }
})

// Basic request
http.get('http://httpbin.org/get?arg=one')
    .then(result => {
        console.log(result)
    })
    .catch(error => {
        console.error(error)
    })

http.post('http://httpbin.org/post', { field: 'value' })
    .then(result => {
        console.log(result)
    })

// Custom timeout
await http.get('http://httpbin.org/get', {timeout: 10000})

// Using cache
await http.get('http://httpbin.org/get', {cache: 60000}) // one minutes of cache

// Cancelable request
let { request, cancel } = http.get('http://172.164.102.88/', null, true)

request.catch(error => {
    console.log(error)
})

// Download
await http.get('http://httpbin.org/image/jpeg', {download: 'filename'})

setTimeout(cancel, 3000)

Keywords

http

FAQs

Package last updated on 19 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts