How to use tiny-json-http - 10 common examples

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 / _unlock.js View on Github external
function _status(headers) {
        headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
        tiny.put({
          url,
          headers,
        }, function done(err, response) {
          if (err) {
            console.log(err)
          }
          else {
            callback(response.body, headers)
          }
        })
      }
    )
github ryanblock / august-connect / src / _unlock.js View on Github external
function pickTheLock(data, headers) {
        let locks = Object.keys(data)
        // Make sure we never, ever lock or unlock the wrong lock
        if (locks.length > 1) {
          throw Error('If you own multiple locks, you must specify which lock to lock.')
        }
        lockID = locks[0]
        const url = 'https://api-production.august.com/remoteoperate/' + lockID + '/unlock'
        headers['Content-Length'] = 0
        tiny.put({
          url,
          headers,
        }, function done(err, response) {
          if (err) {
            console.log(err)
          }
          else {
            callback(response.body, headers)
          }
        })
      }
    )
github ryanblock / august-connect / src / _status.js View on Github external
function _status(headers) {
        headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
        tiny.put({
          url,
          headers,
        }, function done(err, response) {
          if (err) {
            console.log(err)
          }
          else {
            callback(response.body, headers)
          }
        })
      }
    )
github ryanblock / august-connect / src / _lock.js View on Github external
function _status(headers) {
        headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
        tiny.put({
          url,
          headers
        }, function done(err, response) {
          if (err) {
            console.log(err)
          }
          else {
            callback(response.body, headers)
          }
        })
      }
    )
github ryanblock / august-connect / src / _lock.js View on Github external
function pickTheLock(data, headers) {
        let locks = Object.keys(data)
        // Make sure we never, ever lock or unlock the wrong lock
        if (locks.length > 1) {
          throw Error('If you own multiple locks, you must specify which lock to lock.')
        }
        else {
          lockID = locks[0]
          let statusEndpoint = 'https://api-production.august.com/remoteoperate/' + lockID + '/lock'
          headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
          tiny.put({
            url: statusEndpoint,
            headers
          }, function done(err, response) {
            if (err) {
              console.log(err)
            }
            else {
              callback(response.body, headers)
            }
          })
        }
      }
    )
github ryanblock / august-connect / src / _status.js View on Github external
function pickTheLock(data, headers) {
        // TODO maybe enable this method to return status of all locks?
        const locks = Object.keys(data)
        lockID = locks[0]
        const url = 'https://api-production.august.com/remoteoperate/' + lockID + '/status'
        headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
        tiny.put({
          url,
          headers,
        }, function done(err, response) {
          if (err) {
            console.log(err)
          }
          else {
            callback(response.body, headers)
          }
        })
      }
    )
github ryanblock / august-connect / src / _locks.js View on Github external
function _locks(headers) {
      headers['Content-Length'] = 0 // endpoint requires `Content-length: 0` or it won't hang up ¯\_(ツ)_/¯
      tiny.get({
        url,
        headers
      }, function done(err, response) {
        if (err) {
          console.log(err)
        }
        else {
          callback(response.body, headers)
        }
      })
    }
  )
github architect / architect / test / slow / sandbox / 00-html.js View on Github external
test('can read /', t=> {
  t.plan(2)
  tiny.get({
    url: `http://localhost:${port}/`
  },
  function _got(err, data) {
    if (err) {
      t.fail(err)
      console.log(err)
    }
    else {
      t.ok(true, 'got /')
      t.equals('hello world', data.body, 'is hello world')
      console.log({data})
    }
  })
})
github architect / architect / test / slow / sandbox / 01-json.js View on Github external
test('can read /api', t=> {
  t.plan(2)
  tiny.get({
    url: `http://localhost:${port}/api`
  },
  function _got(err, data) {
    if (err) {
      t.fail(err)
      console.log(err)
    }
    else {
      t.ok(true, 'got /')
      t.equals('world', data.body.hello, 'is hello world')
      console.log(data)
    }
  })
})

tiny-json-http

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

Apache-2.0
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Similar packages