Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

JSON Endpoint Demo1

node v4.9.1
version: 2.0.0
endpointsharetweet
// https://runkit.com/runkit/json-endpoint-example-1 // Test with https://runkit.io/suntong/json-endpoint-demo1/branches/master?url=http://google.com, // https://runkit.io/runkit/json-endpoint-example-1/branches/master?url=http://google.com var endpoint = require("@runkit/runkit/json-endpoint/1.0.0") var request = require("request") // peer dependency var requestPromise = require("request-promise") var cheerio = require("cheerio") endpoint(module.exports, async function(request) { try { var html = await requestPromise(request.query.url) var page = cheerio.load(html) } catch(e) { return {error: "could not retrieve page"} } return { title: page("title").text() || "no title", ok: true } })
https://runkit.io/suntong/json-endpoint-demo1/branches/master?url=http://google.com
Loading…

no comments

    sign in to comment