From b552134eecb3f8f24f24b9c6a7bf705b6d6a3246 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 24 Feb 2022 01:07:28 +0000 Subject: [PATCH] Sender: Add .json() --- Server/Sender.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Server/Sender.mjs b/Server/Sender.mjs index d37fceb..4a84652 100644 --- a/Server/Sender.mjs +++ b/Server/Sender.mjs @@ -37,6 +37,15 @@ class Sender { html_string(status_code, html_string) { this.string(status_code, "text/html", html_string); } + /** + * Sends a given thing of any type as a JSON response. + * @param {number} status_code The status code to return. + * @param {any} obj The thing to send - will be converted to JSON. + * @return {void} + */ + json(status_code, obj) { + this.string(status_code, "application/json", obj); + } /** * Sends a given string with a given content-type. * @param {number} status_code The status code to return.