diff --git a/sample/init.js b/sample/init.js index f4f7971d..b45b381c 100644 --- a/sample/init.js +++ b/sample/init.js @@ -13,5 +13,20 @@ server.onload(() => { server.util.log("--- called after all modules loaded ---"); }); +// adding URL endpoints on the server +server.path.full({ + // register the endpoint "/postit" + "/postit": (req, res, next) => { + let chunks = []; + req.on('data', data => { + chunks.push(data.toString()); + }); + req.on('end', () => { + let data = chunks.join(''); + server.util.log({server_received: data}); + res.end(`received ${data.length} bytes`); + }); + } +}); }; diff --git a/sample/kiri.js b/sample/kiri.js index 18a31d66..a69d4881 100644 --- a/sample/kiri.js +++ b/sample/kiri.js @@ -3,4 +3,12 @@ console.log('--- in the browser main loop ---'); // the kiri api starts around line `260` of `src/kiri/main.js` kiri.load(function(api) { console.log('--- kiri startup complete ---'); + + // send data to our "/postit" endpoint + fetch("/postit", { + method: "POST", + body: "this is a test of the POST url endpoint" + }).then(res => res.text()).then(text => { + console.log({server_said: text}); + }); });