From 110e6078390d2e86e6805702b34817f2fee45d4a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 23 Jan 2016 10:57:27 -0500 Subject: [PATCH] add json api example --- contrib/tools/api/post.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 contrib/tools/api/post.js diff --git a/contrib/tools/api/post.js b/contrib/tools/api/post.js new file mode 100644 index 0000000..0b0b3b3 --- /dev/null +++ b/contrib/tools/api/post.js @@ -0,0 +1,42 @@ +var http = require('http'); + +req = { + message: "test api", + frontend: "benis.tld", + name: "benisname", + subject: "ayyyyyy testing api", + /* + file: { + name: "benis.gif", + type: "image/gif", + data: // base64'd string here + }, + */ + email: "sage", + ip: "8.8.8.8", + dubs: false, + reference: "", + newsgroup: "overchan.test" +} + +j = JSON.stringify(req); + +var r = http.request({ + port: 8800, + method: "POST", + path: "/api/post", + auth: "user:pass", + headers: { + "Content-Type": "text/json", + "Content-Length": j.length + } +}, function (res) { + res.on('data', function (chunk) { + var r = chunk.toString(); + var rj = JSON.parse(r); + console.log(rj.id); + }); +}); + +r.write(j); +r.end();