Microservices in Runkit with jsonbin.io!

node v8.17.0
version: 1.0.0
endpointsharetweet
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 })) }
Loading…

no comments

    sign in to comment