Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Latest commit

 

History

History
39 lines (29 loc) · 952 Bytes

Handler.md

File metadata and controls

39 lines (29 loc) · 952 Bytes

Request Handler

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) => {
    //..
}