From: Carl Worth Date: Sun, 26 Apr 2020 22:15:53 +0000 (-0700) Subject: Extend our simple web API with a new /register endpoint X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=7e3a39fd3b9a2c828b6aa8fc1a4fa3e5dd9907b4;p=empires-server Extend our simple web API with a new /register endpoint Which uses body-parser and simply prints out the body of the request. This can now be tested with curl by something as simple as: curl -i -X POST -H "Content-Type: application/json" -d '{"foo": "bar"}' localhost:3000/register --- diff --git a/server.js b/server.js index d66ca29..46eda0a 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,19 @@ const express = require("express") +const body_parser = require("body-parser"); const app = express(); +app.use(body_parser.urlencoded({ extended: false })); +app.use(body_parser.json()); + app.get('/', function (req, res) { res.send('Hello World!'); }); +app.post('/register', function (req, res) { + console.log(req.body); +}); + app.listen(3000, function () { console.log('Example app listening on port 3000!'); });