本文整理匯總了TypeScript中needle.put函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript put函數的具體用法?TypeScript put怎麽用?TypeScript put使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了put函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: API_put
function API_put() {
var nested = {
params: {
are: {
also: 'supported'
}
}
};
needle.put('https://api.app.com/v2', nested, function (err, resp) {
console.log('Got ' + resp.bytes + ' bytes.') // another nice treat from this handsome fella.
});
}
示例2: FileUpload
function FileUpload() {
var data = {
foo: 'bar',
image: { file: '/home/tomas/linux.png', content_type: 'image/png' }
};
needle.post('http://my.other.app.com', data, { multipart: true }, function(err, resp, body) {
// needle will read the file and include it in the form-data as binary
});
needle.put('https://api.app.com/v2', fs.createReadStream('myfile.txt'), function(err, resp, body) {
// stream content is uploaded verbatim
});
}
示例3: API_put
function API_put() {
const nested = {
params: {
are: {
also: 'supported'
}
}
};
// using promises
needle('put', 'https://api.app.com/v2', nested)
.then((resp) => {
console.log(`Got ${resp.bytes} bytes.`); // another nice treat from this handsome fella.
});
// using callback
needle.put('https://api.app.com/v2', nested, (err, resp) => {
console.log(`Got ${resp.bytes} bytes.`); // another nice treat from this handsome fella.
});
}
示例4: FileUpload
function FileUpload() {
const data = {
foo: 'bar',
image: { file: '/home/tomas/linux.png', content_type: 'image/png' }
};
// using promises
needle('post', 'http://my.other.app.com', data, { multipart: true })
.then((resp) => {
// needle will read the file and include it in the form-data as binary
});
needle('put', 'https://api.app.com/v2', fs.createReadStream('myfile.txt'))
.then((resp) => {
// stream content is uploaded verbatim
});
// using callback
needle.post('http://my.other.app.com', data, { multipart: true }, (err, resp, body) => {
// needle will read the file and include it in the form-data as binary
});
needle.put('https://api.app.com/v2', fs.createReadStream('myfile.txt'), (err, resp, body) => {
// stream content is uploaded verbatim
});
}