Express-Endpoint Demo

node v4.8.5
version: 2.0.0
endpointsharetweet
var tonicExpress = require("@runkit/runkit/express-endpoint/1.0.0") // Just provide the exports object to the tonicExpress helper var app = tonicExpress(module.exports) var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.get("/", (req, res) => res.send("Hey!")) app.get("/:name", (req, res) => { res.send(`Hello ${req.params.name}!`) }) app.post("/echo-form", (req, res) => { var formData = Object.keys(req.body).map( k => `${k}: ${req.body[k]}` ) res.type("text/plain") res.send(formData.join("\n")) })
Once you create your Express app with the tonicExpress helper, it works like any other Express app. You can use middleware, declare routes, etc.
Loading…

4 comments

  • posted a year ago by wrg99
    https://nodejs.org/docs/v0.10.40/api/http.html#http_class_http_serverresponse
  • posted a year ago by abol
    👍 Omar aljabli
  • posted 3 months ago by imhomos
    #imhomos
  • posted 2 months ago by 59c940eec9e046001256f18e
    Is `tonicExpress` a legacy name? In other words, if you had written this Notebook today, would you have named that variable `runkitExpress` instead?

sign in to comment