rop的noejs客户端
生活随笔
收集整理的這篇文章主要介紹了
rop的noejs客户端
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
rop_client
rop框架的nodejs客戶端,可以快速聯接rop相關的服務端
intall
npm install rop_client建議使用 npm.taobao.org 源來安裝,詳見?npm.taobao.org
使用rop_client
首先引用rop_client:
let {RichServiceRequest,UploadFile,RopUtils,ShaUtils} =require("rop_client");RichServiceRequest
1.RichServiceRequest構建一個請求類(例子):
let {RichServiceRequest} = require("rop_client"); export default class extends RichServiceRequest{constructor() { //構造函數super();this.v="1.0";this.method="ping";} }2.生成ropUtils(需有services_url地址,app_key,app_secret)
let ropUtils=new RopUtils(clientInfo.services_url,clientInfo.app_key,clientInfo.app_secret);3.然后請求服務:
const duAsync = async() => {let pingRequest=new PingRequest();let response=await ropUtils.doPostByObj(pingRequest);console.log(response);//返回{sucess:true}... }; duAsync();4.有參數上傳參考:
export default class extends RichserviceRequest{constructor(applyNo) { //構造函數super(applyNo);this.v="1.0";this.method="sign.link.file";//以下為其它屬性this.applyNo=applyNo;}/**驗證方法,如果類中寫入此方法則會先運行validate()有錯執出Error*/validate(){this.applyNo=this.trim(this.applyNo);if(this.applyNo==''){throw new Error("applyNo is null");}return super.validate();} }5.對于有文件上傳的情況,繼承RichServiceRequest,并設置屬行file,file后面傳入值
let uploadFile=new UploadFile(); request.file=await uploadFile.init("/tmp/test.pdf"); let response=await ropUtils.doPostByObj(pingRequest);6.RichserviceRequest特殊方法:
//validate 方法,驗證方法,請求服務前會校驗此方法 //getIgnoreSign 返回字符串數組,上傳時運行此方法,這個方法返回的字段不會加入簽名(一般文件字段不做簽名) //trim 處理字段為空的處理,轉null空為http請求接收能為空的''轉載于:https://my.oschina.net/yifanxiang/blog/790501
總結
以上是生活随笔為你收集整理的rop的noejs客户端的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot 详解 (四)red
- 下一篇: 使用graphite和grafana进行