Request flow in Lesan
We only accept two types of HTTP methods in Lesan:
- GET
- POST
GET Requests:
We accept two models of GET requests:
-
Requests sent to serve a
staticdocument.
In order to receive astaticdocument with aGETrequest, you must first allow itspathto Lesan, for this you only need to add the following settings when calling therunServerfunction:coreApp.runServer({ staticPath: ["/pictures", "/videos"] });The
staticPathkey receives anarrayofstringsNow all the files in the
picturesorvideosfolder will be accessible by sending aGETrequest, for example:https://www.xyz.com/pictures/avatar.png -
Requests sent to receive
playground staticdocuments or access to theplaygrounditself.
In order to access theplayground, you must set theplaygroundentry in therunServerfunction equal totrue.coreApp.runServer({ playground: true });The
playgroundkey receives abooleanvalue.Now you can access the
playgroundby sending aGETrequest to an address similar tohttp://localhost:1367/playground.
Note that the following addresses will be accessible together with theplaygroundand will send the necessarydatato run theplayground:- /playground/static/index.css
which sends the necessarystylesfor theUIin theplayground. - /playground/static/bundle.js
which sends aJS bundleof all the codes needed to run theplayground. - /playground/static/get/schemas
which sends twoJSONdata,schemasandacts, which contain all the information we need in theplaygroundto sendrequeststo theserver.
- /playground/static/index.css
POST Requests:
We accept two models of POST requests:
- Requests sent to
receive datafrom theserver(in fact, these requests are the main requests sent to Lesan). - Requests sent to
uploada document.
Receive data
To receive data from the Lesan server, you must send a POST request to the final address of Lesan.
In the body of this request, must be an object in JSON format with the following keys:
- The
servicekey is used to select one of themicroservicesset on the application. This key is optional and by default the value ofmainis placed in it. - The
modelkey is used to select one of theModelsadded to the application. - The
actkey is used to select one of theActsadded to the application. - The
detailskey is used to receive data to be sent from the client side along with data to be delivered to users. This key has two internal keys calledgetandset, we talked a little about it before.set: It contains the information we need in theActfunction.get: Contains selected information that the user needs to be returned. This selection is based onzeroorone. Therefore, we can pass this object directly to MongoDBprojection.
An example of this JSON object is as follows:
{
"service": "main",
"model": "country",
"act": "addCountry",
"details": {
"set": {
"name": "Iran",
"population": 85000000,
"abb": "IR"
},
"get": {
"_id": 1,
"name": 1,
"population": 1,
"cities": {
"name": 1,
"population": 1,
}
}
}
}
This request finally reaches the function we specified for Act to extract the necessary information from it and return the information requested by the user.
If you remember, we set up each Act as follows:
coreApp.acts.setAct({
schema: "user",
actName: "addUser",
validator: addUserValidator(),
fn: addUser,
preValidation: [setUser, checkLevel],
preAct: [justAdmin],
validationRunType: "create",
});
Upload documents
For uploading a document you should send a POST request to Lesan endpoint.