當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript needle.post函數代碼示例

本文整理匯總了TypeScript中needle.post函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript post函數的具體用法?TypeScript post怎麽用?TypeScript post使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了post函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Multipart

function Multipart() {
    const buffer = fs.readFileSync('/path/to/package.zip');

    const data = {
        zip_file: {
            buffer,
            filename: 'mypackage.zip',
            content_type: 'application/octet-stream'
        }
    };

    // using promises
    needle('post', 'http://somewhere.com/over/the/rainbow', data, { multipart: true })
        .then((resp) => {
            // if you see, when using buffers we need to pass the filename for the multipart body.
            // you can also pass a filename when using the file path method, in case you want to override
            // the default filename to be received on the other end.
        });

    // using callback
    needle.post('http://somewhere.com/over/the/rainbow', data, { multipart: true }, (err, resp, body) => {
        // if you see, when using buffers we need to pass the filename for the multipart body.
        // you can also pass a filename when using the file path method, in case you want to override
        // the default filename to be received on the other end.
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:26,代碼來源:needle-tests.ts

示例2: API_post

function API_post() {
    var options = {
        headers: { 'X-Custom-Header': 'Bumbaway atuna' }
    };

    needle.post('https://my.app.com/endpoint', 'foo=bar', options, function (err, resp) {
        // you can pass params as a string or as an object.
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:needle-tests.ts

示例3: 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
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:13,代碼來源:needle-tests.ts

示例4: function

	inviteUserToSlack: function(user) {
		var url = 'https://' + sails.config.slack.communityName + '.slack.com/api/users.admin.invite?t=' + Date.now();
		var data = {
			email: user.email,
			channels: "C051QDDUU,C051QDJJN",
			first_name: user.username,
			token: sails.config.slack.token,
			set_active: true
		};
		Needle.post(url, data, function(err, resp) {
			if (err) PrettyError(err, "An error occurred while inviting a user to slack:")
		});
	}
開發者ID:ModMountain,項目名稱:web-old,代碼行數:13,代碼來源:SlackService.ts

示例5: MultipartContentType

function MultipartContentType() {
    var data = {
        token: 'verysecret',
        payload: {
            value: JSON.stringify({ title: 'test', version: 1 }),
            content_type: 'application/json'
        }
    }

    needle.post('http://test.com/', data, { timeout: 5000, multipart: true }, function(err, resp, body) {
        // in this case, if the request takes more than 5 seconds
        // the callback will return a [Socket closed] error
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:14,代碼來源:needle-tests.ts

示例6: API_post

function API_post() {
    const options = {
        headers: { 'X-Custom-Header': 'Bumbaway atuna' }
    };

    // using promises
    needle('post', 'https://my.app.com/endpoint', 'foo=bar', options)
        .then((resp) => {
            // you can pass params as a string or as an object.
        });

    // using callback
    needle.post('https://my.app.com/endpoint', 'foo=bar', options, (err, resp) => {
        // you can pass params as a string or as an object.
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:16,代碼來源:needle-tests.ts

示例7: publishWebhook

function publishWebhook(message: Message, url: string) {
    const options = {
        json: true,
    };

    needle.post(url, message, options, (err, res) => {
        if (err) {
            return false;
        }

        if (res.body && res.body.error) {
            return false;
        }

        return true;
    });
}
開發者ID:lovett,項目名稱:notifier,代碼行數:17,代碼來源:publish-message.ts

示例8: sendContactEmail

export function sendContactEmail(req, res) {
  const DOMAIN = 'sandbox587d48a9dc7c4ef696a3a149c2d9747d.mailgun.org';
  let KEY = 'key-998712bea03a50212c650813b823352f';
  let options = req.body;

  let recipient = (process.env.NODE_ENV !== 'production') ?
    'qiyen77@gmail.com' :
    ['proair@proairmarine.com','shiamary@proairmarine.com'];

  needle.post(`https://api:${KEY}@api.mailgun.net/v3/${DOMAIN}/messages`, {
    from: options.email,
    to: recipient,
    subject: `Email from ${options.name} titled: ${options.title}`,
    text: options.message,
  }, (err, response) => (err) ?
    res.status(200).json({ sent: false, data: err }) :
    res.status(200).json({ sent: true, data: response.body }));
}
開發者ID:kennyqiyenkan,項目名稱:Proair-Web,代碼行數:18,代碼來源:api.ts

示例9: function

 }).then(function (transaction:Transaction) {
   Needle.post(transaction.paypalExecuteUrl, {
     payer_id: payerId
   }, function (err, resp) {
     if (err) {
       PrettyError(err, "An error occurred during Needle.post inside AddonsController.paypalCheckoutGET:");
       req.flash('error', "Something went wrong during PayPal checkout, please try again.");
       res.redirect('/addons/' + addonId)
     } else {
       Addon.findOne(addonId)
         .then(function (addon:Addon) {
           transaction.inProgress = false;
           req.user.sentTransactions.add(transaction);
           addon.author.receivedTransactions.add(transaction);
           // If the user bought a paid addon we need to track the purchase
           if (addon.price > 0) {
             req.user.purchases.add(addon);
           }
           if (transaction.couponCode !== undefined) addon.incrementCoupon(transaction.couponCode);
           addon.author.balance += amountToCharge;
           return [addon, req.user.save(), addon.author.save(), transaction.save()];
         }).spread(function (addon) {
           if (addon.price === 0) {
             NotificationService.sendUserNotification(addon.author, "MEDIUM", req.user.username + " donated $" + transaction.amount / 100 + " USD to your addon, '" + addon.name);
             req.flash('success', 'Donation success');
           } else {
             NotificationService.sendUserNotification(addon.author, "MEDIUM", req.user.username + " purchased your addon, '" + addon.name + "' for $" + transaction.amount / 100);
             req.flash('success', 'Purchase success');
           }
           FeeService.chargeFee(addon.author);
           res.redirect('/addons/' + addonId);
         }).catch(function () {
           PrettyError(err, "An error occurred during Addon.findOne inside AddonsController.paypalCheckoutGET:");
           req.flash('warning', "Something went wrong but your purchase succeeded. You may be contacted by support.");
           res.redirect('/addons/' + addonId)
         })
     }
   })
 }).catch(function (err) {
開發者ID:ModMountain,項目名稱:web-old,代碼行數:39,代碼來源:AddonsController.ts

示例10: 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
    });
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:24,代碼來源:needle-tests.ts


注:本文中的needle.post函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。