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

road-http

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

road-http

一个网络请求封装

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

对javascript的ajax的封装

import road from "road"

//默认使用get请求
road("/")
.setData({})
.request((res)=>{
	console.log(res)
})

//也可以调用get方法发起请求,可以这样调用 put 、post、delete等请求方法
road.get("/")
	.setHeader({
		"Content-type":"application/json"
	})
	.request((res)=>{
		console.log(res)
	})

// 也可以使用object来调用
road({
	type:"GET",
	header:{
		"COntent-type":"application/json"
	},
	data:{}, //需要发送到服务器的数据
	actionType:"REQUEST_SUCCESS",  // 在redux环境下可以设定actionType来将请求数据保存到store中
	success:(res)=>{},
	error:(res)=>{}, //请求错误时的调用函数 ,不定义将使用setDefaultError定义的默认错误处理函数
}).request()


// 可以通过设置delay来启动轮询请求
let loop = road.get("/")
loop.setDelay(1000) //设置轮询的请求间隔
loop.request((res)=>{
	console.log(res)
})

// 调用cancelLoop 取消轮询
loop.cancelLoop()

Keywords

http

FAQs

Package last updated on 20 Nov 2017

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