Package Exports
- tiny-json-http
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tiny-json-http) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tiny-json-http
Minimalist HTTP client for GET and POSTing JSON payloads
- Zero dependencies: perfect for AWS Lambda or Browserify
- Sensible default: assumes buffered JSON responses
- System symmetry: Node style errback API, or Promises for use with Async/Await
npm i tiny-json-http --saveapi
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
urlrequireddataform vars fortiny.post,tiny.put, andtiny.deleteotherwise querystring vars fortiny.getheaderskey/value map used for headers
callback values
erra real javascriptErrorif there was onedataan object withheadersandbodykeys
promises
- if no
callbackis provided to the tiny-json-http methods, a promise is returned - perfect for use of async/await
example
With Async / Await
var tiny = require('tiny-json-http')
var url = 'http://www.randomkittengenerator.com'
(async () => {
try {
const result = await tiny.get({url})
console.log(result)
} 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 __got(err, result) {
if (err) {
console.log('ruh roh!', err)
}
else {
console.log(result)
}
})Check out the tests for more examples! 💟