本文整理匯總了TypeScript中request.put函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript put函數的具體用法?TypeScript put怎麽用?TypeScript put使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了put函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should return put', (done) => {
request.put(localBaseUrl + '/put', (err, res, body) => {
let data = assertResponse(err, res, body);
assert.equal(data, 'put');
done();
});
});
示例2: storeInternal
storeInternal(doc: { Id: string }, cb: (err: any, doc: any) => void ) {
var headers = {
"Content-Type": "application/json; charset=utf-8",
"Raven-Entity-Name": this.getEntityName(doc),
"If-Match": "00000000-0000-0000-0000-000000000000"
}
var id = doc.Id
if (doc["@metadata"]) {
headers = this.getHeadersFromMetadata(doc["@metadata"], headers)
delete doc["@metadata"].etag;
}
delete doc.Id;
var opts = {
url: "" + this.host + "databases/" + this.db + "/docs/" + id,
headers: headers,
body: this.serializer.stringify(doc)
};
request.put(opts, (error, response, body) => {
if (!error && response.statusCode === 201) {
var key = this.serializer.parse(body);
doc.Id = key.Key;
return cb(null, doc);
} else {
return cb(error || response, null);
}
});
}
示例3: Promise
return new Promise((resolve, reject) => {
request.put(url, options, (error, response, body) => {
if (error) {
return reject(error);
}
resolve({response, body});
})
})
示例4: it
it('should handle RestErrors', (done) => {
request.put({
headers: { 'Accept': 'text/html' },
url: 'http://localhost:5674/accept/conflict',
}, function(error, response, body) {
expect(response.statusCode).to.eq(409);
done();
});
});
示例5: it
it('should not authorize in PUT method', (done) => {
request.put('http://localhost:5674/authorization/methods/profile', {
headers: {
'Authorization': `Bearer ${generateJwt()}`
}
}, (error, response, body) => {
expect(response.statusCode).to.eq(403);
done();
});
});
示例6: request
// Make a request to API.
// Syntax: .request(method, uri, [query], callback)
private request(method: string, uri: string, argsOrCallback?: any | RequestCallback, callback?: RequestCallback): void {
let args: any;
if (callback) {
args = argsOrCallback;
} else {
callback = argsOrCallback;
args = {};
}
let url = apiBaseUri + (uri[0] === "/" ? "" : "/") + uri;
if (method === "GET" || method === "DELETE") {
url += "?" + querystring.stringify(this.parseQuery(uri, args));
}
let options: request.Options = {
url: url,
method: method,
oauth: {
consumer_key: config.get("externalApp.consumer_key"),
consumer_secret: config.get("externalApp.consumer_secret"),
token: config.get("externalAppUser.token"),
token_secret: config.get("externalAppUser.token_secret"),
},
json: true,
};
let requestCallback = function (err: any, response: any, body: any): void {
if (!err && response.statusCode >= 400) {
err = new Error(body);
err.statusCode = response.statusCode;
err.responseBody = body;
err.statusMessage = http.STATUS_CODES[response.statusCode];
}
callback(err, body);
};
switch (method.toLowerCase())
{
case "get":
request.get(options, requestCallback);
break;
case "post":
request.post(options, requestCallback);
break;
case "put":
request.put(options, requestCallback);
break;
case "delete":
request.delete(options, requestCallback);
break;
}
};
示例7: Promise
return new Promise(resolve => {
request.put(
{
url: `${baseUrl}/${path}`,
headers: {
'Authorization': `Basic ${auth}`,
'Content-Type': 'application/json',
'User-Agent': 'request'
},
body: JSON.stringify(body)
},
(_err, resp, _body) => {
resolve(resp);
}
);
});
示例8: function
function(resolve, reject) {
request.put({
url: config.baseurl + path,
headers: {
'Content-Type': 'application/json',
'clientID': clientId,
'msaID': msaId,
'accessToken': accessToken,
'nonce': uuidString
},
form: jsonBody
},
function(err,httpResponse,body){
resolve(body);
})
});