Add parser API
This commit is contained in:
parent
1d2e0726da
commit
6236669e4b
1 changed files with 39 additions and 0 deletions
39
scripts/ParserAPI.js
Normal file
39
scripts/ParserAPI.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
const Messaging = require('./messaging').Messaging;
|
||||
const RequestParser = require(`./RequestParser`).RequestParser;
|
||||
|
||||
class ParserAPI {
|
||||
/*
|
||||
Custom paths used for the API.
|
||||
*/
|
||||
#paths = {
|
||||
"parser": "/whoami"
|
||||
}
|
||||
|
||||
/*
|
||||
Create the header parser API.
|
||||
|
||||
@param {Express} INSTANCE - The Express instance
|
||||
*/
|
||||
constructor(INSTANCE) {
|
||||
this[`instance`] = INSTANCE;
|
||||
|
||||
this.receive();
|
||||
}
|
||||
|
||||
/*
|
||||
Receive requests.
|
||||
*/
|
||||
receive() {
|
||||
[`get`, `post`].forEach((METHOD) => {
|
||||
this[`instance`][METHOD](`/api${this.#paths["parser"]}`, (REQUEST, RESPONSE) => {
|
||||
try {
|
||||
let PARSER = new RequestParser(REQUEST);
|
||||
RESPONSE.json(PARSER.getHeaders());
|
||||
} catch(ERROR) {Messaging.exception(RESPONSE, ERROR)}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {ParserAPI}
|
Loading…
Add table
Add a link
Reference in a new issue