本文整理汇总了TypeScript中superagent.put函数的典型用法代码示例。如果您正苦于以下问题:TypeScript put函数的具体用法?TypeScript put怎么用?TypeScript put使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
function(
resolve : (jsonObject : IUpdate) => void,
reject : (error : ActionError) => void) : void {
request
.put("/api/companies/" + data.company_id + "/users/"
+ data._id + "/credentials")
.send(
{ username: data.username,
password : encryptedPasswordOP,
newUsername: data.newUsername,
newPassword: encryptedPasswordNP
})
.set("Accept", "application/json")
.set("x-access-token", data.token)
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let updateUserPasswordResponse :
IUpdate = res.body;
resolve(updateUserPasswordResponse);
}
});
});
示例2: reject
return new Promise<any>((resolve, reject) => {
if (_this.auth) {
superagent.put(_this.couchdb + "/" + obj._id).set('Content-Type', 'application/json').send(JSON.stringify(obj)).auth(_this.auth.user, _this.auth.password).end((err, res) => {
if (err) {
reject(err);
} else {
obj._rev = JSON.parse(res.text).rev;
resolve(obj);
}
})
} else {
superagent.put(_this.couchdb + "/" + obj._id).set('Content-Type', 'application/json').send(JSON.stringify(obj)).end((err, res) => {
if (err) {
reject(err);
} else {
obj._rev = JSON.parse(res.text).rev;
resolve(obj);
}
})
}
})
示例3: function
function(resolve : (jsonObject : ICompanyResponse ) => void,
reject : (error : ActionError) => void) : void {
request
.put("/api/companies/" + company_id)
.set("x-access-token", token)
.send(companyName)
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let updateCompanyResponse :
ICompanyResponse = res.body;
resolve(updateCompanyResponse);
}
});
})
示例4: it
it('should PUT', async () => {
mock.use((req, res) => {
expect(req.method()).to.eq('PUT');
expect(String(req.url())).to.eq('/');
expect(req.body()).to.eq(JSON.stringify({foo: 'bar'}));
return res
.status(200)
.reason('Created')
.header('Content-Length', '12')
.body('Hello World!');
});
const res = await superagent.put('/').send({foo: 'bar'});
expect(res.status).to.eq(200);
// expect(res.statusText).to.eq('Created');
expect(res.header).to.have.property('content-length', '12');
expect(res.text).to.eq('Hello World!');
});
示例5: function
function(
resolve : (jsonObj : IDatabase) => void,
reject : (err : Object) => void) : void {
request
.put("/api/companies/" + data.id_company +
"/database/" + data.id_database)
.set("Content-Type", "application/json")
.set("x-access-token", token)
.send(data)
.end(function(error : Object, res : Response) : void{
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let response : IDatabase = res.body;
resolve(response);
}
});
});
示例6: put
/**
* Builds a HTTP PUT request for the provided `endpoint`.
*
* @hidden
* @param endpoint The endpoint URI, relative to this server’s base URL. Must start with a `/`.
* @return A request object to `PUT` on `endpoint`.
*/
public put(endpoint: string): Http.Request {
return Http.put(this.baseUrl + endpoint);
}
示例7: async
export let ajax: AjaxFunction = async (url, data, type = 0, ajaxType = 'get') => {
//统一添加请求路径
if (url.indexOf('http') != 0) {
url = config.requestUrl + url;
}
let ajaxRequest: superagent.SuperAgentRequest;
let ajaxRecord: AjaxRecord = {
url,
time: new Date(),
data,
type,
ajaxType
};
//创建请求
switch (ajaxType) {
case 'delete':
ajaxRequest = superagent.delete(url);
break;
case 'put':
ajaxRequest = superagent.put(url);
break;
case 'get':
ajaxRequest = superagent.get(url);
break;
case 'post':
ajaxRequest = superagent.post(url);
break;
}
//创建请求数据
if (data) {
ajaxRequest = ajaxRequest.send(data);
}
//添加请求记录 反向添加
ajaxRecordArray.unshift(ajaxRecord);
let typeFunctionValue = await typeFunctionArray[type](url, data, type, ajaxType, ajaxRecord);
if (typeFunctionValue) {
return typeFunctionValue;
}
let promiseFunction = (reslove, reject) => {
//发送请求
ajaxRequest.end((error, res) => {
ajaxRecord.response = res;
if (error) {
errorMsg({
message: `请求错误!`,
description: 'status:${res.status}'
});
reject(ajaxRecord.responseDate);
} else {
try {
ajaxRecord.responseDate = JSON.parse(res.text);
} catch (error) {
ajaxRecord.responseDate = {
status: 0,
data: res.text,
message: ''
};
}
reslove(ajaxRecord.responseDate);
}
})
}
return new Promise<AjaxData>(promiseFunction);
}
示例8:
return Promise.fromCallback(callback => {
return this.auth(put(this.papiUrl('/batches/' + this.currentBatchId +'/'))).end(callback);
})