41 lines
801 B
JavaScript
41 lines
801 B
JavaScript
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;
|