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 Example 1

node v4.9.1
version: 1.0.0
endpointsharetweet
Send a request to a URL like https://runkit.io/runkit/json-endpoint-example-1/branches/master?url=http://google.com, get back the title of the page in the url query parameter.
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" } })
Because we're using async/await, we're automatically returning a Promise. You can always explicitly return a promise too.
Loading…

9 comments

  • posted 4 years ago by randomstand
    Wow..
  • posted 4 years ago by 5ec98e10c29904001bf9f92a
    Tf t te k
  • posted 3 years ago by escobar-20
    Hi all
  • posted 2 years ago by matt-destroyer
    Doesn't seem to work for any available version of NodeJS above v6.17.1 ...
  • posted a year ago by 635660925cd0e8000841ae50
    TFX
  • posted a year ago by 641878517dda1b000845c95b
    Slot hack example
  • posted a year ago by waiyanpaingsoe
    online game slot hack example
  • posted 6 months ago by kara021
    Thats İt !!!
  • posted 2 months ago by nifp909
    Thanks

sign in to comment