Microservices in Runkit with jsonbin.io!
const JSONBIN_TARGET = 'https://api.jsonbin.io/b/5adfe2ed003aec63328dd924'
const got = require('got')
async function fetchHits () {
const json = await got(`${JSONBIN_TARGET}/latest`)
return JSON.parse(json.body).hits || 0
}
function increment (hits = 0) {
return got.put(JSONBIN_TARGET, {
json: true,
body: {
hits: ++hits
}
})
}
exports.endpoint = async function (req, res) {
let hits = await fetchHits()
await increment(hits)
res.end(JSON.stringify({ hits, remoteAddress: req.connection.remoteAddress }))
}
no comments