A request handler can be added from file system or from code;
const app = Muneem({
handlers : "path/for/request/handlers",
//services: "path/for/services",
})
app.add("handler", "name", fn);
//app.addHandler("name", fn);
app.start();
A handler accepts 3 arguments: HttpAsked, HttpAnswer, Store.
A store is the collection of shared resources which can be added as app.set("name", resource)
.
module.exports = async (asked, answer, giveMe) => {
const data = await asked.readJson();//read request data
var db = giveMe("mongo"); //shared resources
//..
anwser.writeJson( data );//response back
}
A handler added from the file system should have //@handler
, or //@service
, which helps to differentiate other code from request handlers
//@handler
//.. some code
module.exports = (asked,answer) => {
//..
}