How to use the tiny-json-http.post function in tiny-json-http

To help you get started, we’ve selected a few tiny-json-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smallwins / slack / src / _exec.js View on Github external
// api.slack.com/files.upload requires multipart/form-data post
    // which means we need to do a few things differently…
    var isUploading = /files.upload/.test(url)

    // stringify any objects under keys when application/x-www-form-urlencoded
    if (!isUploading) {
      Object.keys(form).forEach(function (key) {
        if (typeof form[key] === 'object') {
          form[key] = JSON.stringify(form[key])
        }
      })
    }

    // always post to slack
    http.post({
      url: `${origin}/api/${url}`,
      headers: {
        'Content-Type': isUploading? 'multipart/form-data' : 'application/x-www-form-urlencoded'
      },
      data: form
    }, 
    function _res(err, res) {
      if (err && err.message === 'POST failed with: 429') {
        // workaround Slacks lack of symmetry not ours…
        var e = Error('ratelimited')
        e.retry = err.raw.headers['retry-after']
        callback(e)
      }
      else if (err) {
        callback(err)
      }
github ryanblock / august-connect / src / _validate.js View on Github external
function _getValidationCode(headers) {
        let data = { value: identifier }
        tiny.post({
          url,
          headers,
          data,
        }, function _done(err) {
          if (err) {
            console.log(err)
          }
          else {
            console.log(`Check ${identifier} for your validation code`)
          }
        })
      }
    )
github ryanblock / august-connect / src / _session.js View on Github external
module.exports = function AugustAccessTokenRequest(callback) {
  tiny.post({
    url,
    headers,
    data,
  }, function _done(err, response) {
    if (err) {
      console.log(err)
    }
    else {
      headers['x-august-access-token'] = response.headers['x-august-access-token']
      callback(headers)
    }
  })
}
github ryanblock / august-connect / src / _validate.js View on Github external
function _validateCode(headers) {
          console.log(headers)
          let data = {
            code
          }
          data[identifierType] = identifier
          tiny.post({
            url,
            headers,
            data,
          }, function _done(err) {
            if (err) {
              console.log(err)
            }
            else {
              console.log('Your session is now validated! Please remove references to the validate methods from your code.')
            }
          })
        }
      )
github thehandsomepanther / slag / lib / chat.command.js View on Github external
function chatcommand(params, callback) {
  tiny.post({
    url: 'https://slack.com/api/chat.command',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: params
  }, function _res(err, res) {
    if (err) console.log(err)
  });
}

tiny-json-http

Minimalist `HTTP` client for `GET`, `POST`, `PUT`, `PATCH` and `DELETE` `JSON` payloads

Apache-2.0
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Similar packages