Complete task “Get Route Parameter Input from the Client”

This commit is contained in:
buzzcode2007 2025-03-08 09:39:53 +00:00
parent 82a6611297
commit c841311ad7
2 changed files with 42 additions and 1 deletions

41
scripts/echo.js Normal file
View file

@ -0,0 +1,41 @@
let express = require('express');
require('dotenv').config();
let app = express();
class EchoServer {
#paths = {
"API": {
"echo": "/:word/echo"
}
}
/* Echo.
WORD (string): The data to be repeated.
returns: (object) the formatted repeat response
*/
echo(WORD) {
let RESPONSE = {"echo": WORD};
return (RESPONSE);
}
/* Create the response.
REQUEST (object): The request object.
RESPONSE (object): The response object.
*/
respond(REQUEST, RESPONSE) {
RESPONSE.json(this.echo(REQUEST.params.word));
}
constructor() {
app.get(this.#paths[`API`][`echo`], (REQUEST, RESPONSE, next) => {this.respond(REQUEST, RESPONSE);})
}
}
new EchoServer();
module.exports = app;