Sender: Add .json()

This commit is contained in:
Starbeamrainbowlabs 2022-02-24 01:07:28 +00:00
parent e301dfd226
commit b552134eec
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 9 additions and 0 deletions

View File

@ -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.