siwi-request
v2.0.0
Published
nodejs https/http 请求库
Downloads
3
Readme
siwi-request
install
use npm
npm install siwi-request
use yarn
yarn add siwi-request
Example
post
const request = require('siwi-request')
class Example {
constructor() {
this.init()
}
async init () {
const uri = 'https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN'
const data = {
test: 'test'
}
const res = await request.post(uri, data)
}
}
module.exports = new Example()
get
const request = require('siwi-request')
class Example {
constructor() {
this.init()
}
async init () {
const uri = 'https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN'
const data = {
test: 'test'
}
const res = await request.get(uri, data)
}
}
module.exports = new Example()
get 参数也可以对象穿进去 也可以带在url上
json
const request = require('siwi-request')
class Example {
constructor() {
this.init()
}
async init () {
const uri = 'https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=ACCESS_TOKEN'
const data = {
"media_id": 1,
"index":1,
"articles": {
"title": 'TITLE',
"thumb_media_id": 'THUMB_MEDIA_ID',
"author": 'AUTHOR',
"digest": 'DIGEST',
"show_cover_pic": 1,
"content": 'CONTENT',
"content_source_url": 'CONTENT_SOURCE_URL'
}
}
const res = await request.json(uri, data)
}
}
module.exports = new Example()
file
const request = require('siwi-request')
const path = require('path')
class Example {
constructor() {
this.init()
}
async init () {
const uri = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE'
const file = path.join(__dirname, 'test.jpg')
const res = await request.file(uri, {file: file})
}
}
module.exports = new Example()
Notice
v2.0 不再区分http https 新增上传文件 针对微信api 开发