Complete task “Get Route Parameter Input from the Client”
This commit is contained in:
parent
82a6611297
commit
c841311ad7
2 changed files with 42 additions and 1 deletions
41
scripts/echo.js
Normal file
41
scripts/echo.js
Normal 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;
|
|
@ -4,7 +4,7 @@
|
||||||
* ***************************************************/
|
* ***************************************************/
|
||||||
|
|
||||||
const bGround = require('fcc-express-bground');
|
const bGround = require('fcc-express-bground');
|
||||||
const myApp = require('./myApp');
|
const myApp = require('./scripts/echo');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue