
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Network request library for labrador and alaska.
Labrador 网络库,适用于 Alaska Restful 格式的服务器接口。
如果服务器发生错误,返回的对象中 error 属性应当为字符串类型的错误信息,如果没有发生错误,error 属性留空。
本库对微信小程序 wx.request 进行了二次封装,尤其是内置了对自定义Session的支持。
import request from 'al-request';
async function test(){
let res=request('my/api');
console.log('res',res);
}
要让上述代码正确运行,我们需要在Labrador配置文件
.labrador中增加常量API_ROOT定义所有请求默认的API根路径,否则调用request方法时必须提供完整URL地址。
{
"define":{
"API_ROOT": "https://maichong.it/"
}
}
在上边的代码中,我们使用了 al-request 导出的默认网络客户端,有些时候我们可能需要自定义网络客户端,例如我们需要调用多个域名下的接口。使用 create 函数创建一个自定义客户端:
import { create } from 'al-request';
const request = create({ apiRoot:'https://your.domain/' });
request.post('user/login',{ username:'liang' });
如果我们需要更新默认客户端的配置,只需要调用其 setOptions 方法:
import request from 'al-request';
request.setOptions({ apiRoot:'https://your.domain/' });
setOptions方法的参数和create方法的参数一致。 通过create方法创建的自定义网络客户端也有setOptions方法。
| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
| apiRoot | string | '' | 服务器API根路径,如果不设置,调用API必须提供完整URL |
| session | boolean | true | 是否打开自定义Session支持 |
| updateKey | string | '_session' | 当服务器返回的JSON对象有此属性时,更新当前SessionID |
| headerKey | string | 'Session' | HTTP请求Session header名称 |
| getSession | Function | 获取当前的SessionID,默认获取 wx.app.sessionId | |
| setSession | Function | 设置新的SessionID,默认保存到 wx.app.sessionId | |
| defaultHeader | Object | 默认Header |
request 的第一个参数指定请求的方法,有效值:OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT,可以省略,默认为 GET
request('my/api') 等价于 request('GET', 'my/api') 等价于 request.get('my/api')
request.post('my/api') 等价于 request('POST', 'my/api')
data 参数为提交的KV数据对象,可以省略,如果请求方法为 POST 或 PUT 时,数据作为HTTP请求BODY,否则将转换为URL Query。
例如 request('my/api',{foo:'bar'}) 将请求 GET http://your.domain/my/api?foo=bar
FAQs
Network request library for labrador and alaska.
We found that al-request demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.