GithubHelp home page GithubHelp logo

krispi1 / tiny-json-http Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brianleroux/tiny-json-http

0.0 0.0 0.0 58 KB

:anchor: Minimalist HTTP client for JSON payloads.

JavaScript 100.00%

tiny-json-http's Introduction

tiny-json-http

Minimalist HTTP client for GET and POSTing JSON payloads

  • Zero dependencies: perfect for AWS Lambda
  • Sensible default: assumes buffered JSON responses
  • System symmetry: Node style errback API, or Promises for use with Async/Await
npm i tiny-json-http --save

api

  • tiny.get(options[, callback])
  • tiny.post(options[, callback])
  • tiny.put(options[, callback])
  • tiny.del(options[, callback)]

*callback is optional, tiny methods will return a promise if no callback is provided

options

  • url required
  • data form vars for tiny.post, tiny.put, and tiny.delete otherwise querystring vars for tiny.get
  • headers key/value map used for headers (including support for uploading files with multipart/form-data)
  • buffer if set to true the response body is returned as a buffer

callback values

  • err a real javascript Error if there was one
  • data an object with headers and body keys

promises

  • if no callback is provided to the tiny-json-http methods, a promise is returned
  • perfect for use of async/await

examples

With Async / Await

var tiny = require('tiny-json-http')
var url = 'http://www.randomkittengenerator.com'

;(async function _iife() {
  try {
    console.log(await tiny.get({url}))
  } catch (err) {
    console.log('ruh roh!', err)
  }
})();

With Callback

var tiny = require('tiny-json-http')
var url = 'http://www.randomkittengenerator.com'

tiny.get({url}, function _get(err, result) {
  if (err) {
    console.log('ruh roh!', err)
  }
  else {
    console.log(result)
  }
})

Check out the tests for more examples! ๐Ÿ’Ÿ

tiny-json-http's People

Contributors

brianleroux avatar bigab avatar janl avatar jasonk avatar jondavidjohn avatar ryanblock avatar nuragic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.